akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 100000
#define M 50000

int binarySearch(int A[], int n, int key){
  int left = 0,mid,right = n;
  while(left < right){
    mid = (left + right) / 2;
    if(A[mid] == key) return 1;
    else if(key < A[mid]) right = mid;
    else left = mid + 1;
  } 
  return 0;
}

int main(){
  int i,n,A[N + 1],q,key,sum = 0;

  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&key);
    if(binarySearch(A,q,key)) sum++;
  }
  printf("%d\n",sum);

  return 0;
}



Measured memory_bytes: 2244
INF = float('inf')
N = int(input())
H = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for _ in range(3)] for _ in range(N+1)]

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

ans = 0
for i in range(3):
    ans = max(ans, dp[N][i])

print(ans)


Measured memory_bytes: 47328
use std::io::Read;

fn main() {
    let mut buff = String::new();
    std::io::stdin().read_to_string(&mut buff).unwrap();

    let mut iter = buff.split_whitespace();
    let k: i32 = iter.next().unwrap().parse().unwrap();

    let a = k / 2;
    let b = (k + 1) / 2;
    println!("{}", a * b);
    ()
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(int, input().split()))

R = {}

for i in range(1 , N):
  t = A[0] + A[i] - i
  if t in R:
    R[t] += 1
  else:
    R[t] = 1

ans = 0
for i in range(N):
  t = -(A[i] - A[0] + i)
  if t in R:
    ans += R[t]

print(ans)

Measured memory_bytes: 40508
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	int n,k,i;
  	cin>>n>>k;
  	int Kh=k-1;
  	int X[n];
  for(i=0;i<n;i++)cin>>X[i];
  	vector <int> listup;
  	for(i=0;i<n-k+1;i++)listup.push_back(abs(X[i]-X[i+k-1])+min(abs(X[i+k-1]),abs(X[i])));
	cout<< *min_element(listup.begin(),listup.end()) << endl;
	return 0;
}

Measured memory_bytes: 1024
N, Y = map(int, input().split())

for x in range((Y // 10000) + 1):
    for y in range(((Y - 10000 * x) // 5000) + 1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()
else:
    print(-1, -1, -1)


Measured memory_bytes: 3060
s = int(input())

def calc(n):
  if n % 2 == 0:
    return n // 2
  else:
    return 3 * n + 1

l = [s]
a = s

for i in range(2, 10000):
  a = calc(a)
  if a in l:
    print(i)
    exit()
  else:
    l.append(a)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
int main(void){
    int n;
    std::cin >> n;
    rep(i, 9){
        if(n / (i + 1) < 10 && n % (i + 1) == 0){
            std::cout << "Yes" << std::endl;
            break;
        }
        if(i == 8){
            std::cout << "No" << std::endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	string s;
	cin >> s;
	vl suf(n, 0);
	suf[n - 1] = (s[n - 1] == 'R' ? 1 : 0);
	for (ll i = n - 2; i >= 0; i--) {
		suf[i] = suf[i + 1];
		if (s[i] == 'R')
			suf[i]++;
	}
	ll ans = min(n - suf[0], suf[0]);
	ll c = (s[0] == 'W' ? 1 : 0);
	for (ll i = 1; i < n - 1; i++) {
		ans = min(ans, max(c, suf[i]));
		if (s[i] == 'W')
			c++;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 5188
import java.util.Scanner;

/**
 * Created by malone on 2018/3/9.
 */
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x, y;

        while (true) {
            int temp;
            x = sc.nextInt();
            y = sc.nextInt();
            if ((x == 0) && (y == 0)) {
                break;
            }

            if (x > y) {
                temp = x;
                x = y;
                y = temp;
            }
            System.out.printf("%d %d\n", x, y);
        }
    }
}



Measured memory_bytes: 40388
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n,m,cnt=0;
  scanf("%d %d",&n,&m);
  vector<int> v(2*n);
  vector<pair<int,int>> p(m);
  rep(i,n) scanf("%d",&v[i]);
  rep(i,m) scanf("%d %d",&p[i].second,&p[i].first);
  sort(p.begin(),p.end());
  for (int i = m-1; i >= 0 && cnt < n; --i)
     rep(j,p[i].second) {
         v[n + cnt++]=p[i].first;
         if(cnt==n) break;
     }
  sort(v.begin(),v.end(),greater<int>());
  long long ans=0;
  rep(i,n) ans+=v[i];
  cout<<ans;
}

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

#define N 2000000

int main() {

  int n;
  cin>>n;

  int a[N], max = 0;
  for(int i = 0; i < n; i++) {
    cin>>a[i];
    if(a[i] > max) max = a[i];
  }

  int A[max+1], AA[max+1];
  for(int i = 0; i <= max; i ++) {
    A[i] = 0;
    AA[i] = 0;
  }

  for(int i = 0; i < n; i++) {
    AA[  a[i]  ]++;
  }

  A[0] = AA[0];
  for(int i = 1; i < max+1; i++) {
    A[i] = A[i-1] + AA[i];
  }

  int b[N];
  for(int i = n-1; i >= 0; i--) {
    b[ A[ a[i] ] - 1] = a[i];
    A[ a[i] ]--;
  }

  int i;
  for(i = 0; i < n-1; i++) cout<<b[i]<<' ';
  cout<<b[i]<<endl;

  return 0;
}



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

int main(){
    string s;
    cin >> s;
    cout << s.at(0) << s.size()-2 << s.at(s.size()-1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int Q,T,F,i;
	string s;
	char c;
	int flag=0;
	cin>>s;
	cin>>Q;
	while(Q--)
	{
		cin>>T;
		if(T==1)flag++;
		else{
			cin>>F>>c;
			if(flag%2==0)
			{
				if(F==1)s.insert(s.begin(),c);
				else s.insert(s.end(),c);
			}
			else{
				if(F==1)s.insert(s.end(),c);
				else s.insert(s.begin(),c);
			}
		}
	}
	if(flag%2==1)reverse(s.begin(),s.end());
	cout<<s;
	return 0;
	
} 


Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

int main(){
    long long int n;
    long long int a[5];
    cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    sort(a, a + 5);
    long long int ans = ceil(n / (double)a[0]) - 1 + 5;
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll p1=a*c;
	ll p2=b*c;
	ll p3=a*d;
	ll p4=b*d;
	ll ans=max(max(p1,p2),max(p3,p4));
	cout<<ans<<endl;
}

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++){
	    cin >> a[i];
	}
	int pre = a[0];
	long long int ans = 0;
	for(int i=1; i<n; i++){
	    if(pre > a[i]){
	        ans = ans + (pre - a[i]);
	    }else{
	        pre = a[i];
	    }
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 4348
#include<bits/stdc++.h>
#define ll long long
#define N 2005
#define oo 1000000000
#define zyy 1000000007
#define int ll
#define For(i,x,y) for(int i=x;i<=y;i++)
#define Rep(i,x,y) for(int i=x;i>=y;i--)
#define Forn(i,x,y) for(int i=x;i<y;i++)
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;
	return f?-x:x;
}
int n;
inline ll gcd(ll x,ll y){
	if(!y) return x;
	else return gcd(y,x%y);
}
ll ans;
main(){
	n=read();ans=read();
	Forn(i,1,n){
		ll x=read();
		ans=ans/gcd(x,ans)*x;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l.begin(),l.end());
    int sum=0;
    for(int i=0;i<n-1;i++){
        sum+=l[i];
    }
    string ret;
    if(l.back()<sum){
        ret="Yes";
    }else{
        ret="No";
    }
    cout<<ret;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 5
main(){
	int num[N];
	int i=0,j,tmp;
	scanf("%d%d%d%d%d",&num[i],&num[i+1],&num[i+2],&num[i+3],&num[i+4]);
	for(j=0;j<N-1;j++){
		for(i=j+1;i<N;i++){
			if(num[j]<num[i]){
				tmp=num[j];
				num[j]=num[i];
				num[i]=tmp;
			}
		}
	}
	i=0;
	printf("%d %d %d %d %d\n",num[i],num[i+1],num[i+2],num[i+3],num[i+4]);
	return 0;
}

Measured memory_bytes: 596
import sys

N = int(input())
H = list(map(int, input().split()))

cnt = 0
for i in range(N - 1):
    if H[i] < H[i + 1]:
        cnt = 0
        continue
    elif H[i] == H[i + 1]:
        continue
    else:
        if H[i] - 1 <= H[i + 1]:
            H[i] -= 1
            cnt += 1
            if cnt >= 2:
                print("No")
                sys.exit()
        else:
            print("No")
            sys.exit()
else:
    print("Yes")

Measured memory_bytes: 14252
package main

import "fmt"

func main() {
        var s string
        var k int
        fmt.Scan(&s, &k)

        i := 0
        for i = range s {
                if s[i] != '1' || k-1 <= i {
                        break
                }
        }
        fmt.Printf("%c\n", s[i])
}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const lb pi=acos(-1);
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  lb a,b;cin>>a>>b;

  out(ll(a*b));

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    map<string,int> S;

    int val_max = 0;
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        S[s]++;
        val_max = max(val_max,S[s]);
    }

    vector<string> ans;
    for(auto itr = S.begin();itr !=S.end();itr++){
        if(itr->second==val_max) ans.push_back(itr->first);
    }

    sort(ans.begin(),ans.end());

    for(int i=0;i<ans.size();i++){
        cout << ans[i] << endl;
    }

    


    
    



}

Measured memory_bytes: 26868
#include<bits/stdc++.h>
#define f first
#define se second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define sz(s) (int)s.size()
#define rep(i,a,b) for( int i=a;i<b;i++)
#define repr(i,a,b) for( int i=a;i>=b;i--)
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(n,m) memset(n,m,sizeof(n))
#define ii pair<int,int>
#define iii tuple<int, int, int>
#define si set<int>
#define vi vector<int>
#define vii vector<ii>
#define mi map<int,int>
#define lb lower_bound
#define ub upper_bound
#define present(s,x) (s.find(x) != s.end())
#define ford(container, it) for(auto it:container)
#define fors(container, it, a, b) for(auto it = a; it != b; it++)
#define Anurag_Gupta ios_base::sync_with_stdio(0);
#define IIIT_ALLD cin.tie(0);cout.tie(0);
#define mod 987654319
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e17
#define int long long
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define gcd(a,b) __gcd(a,b)
using namespace std;
int add(int a, int b, int c){int res=a+b;return(res>=c?res-c:res);}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mul(int a, int b, int c){int res=(int)a*b;return(res>=c?res%c:res);}
template<typename T>T power(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T mdpower(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
/*------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
    Anurag_Gupta
    IIIT_ALLD
 
   
  

    int n,k;
    cin>>n>>k;

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

    vi cycle;

    map<int,int>mp;


    int x = 1;

    while(cycle.size()<=2*n)
    {
        
        cycle.pb(x);
        x = arr[x];
    }

   

    int cycleStartingidx,cycleLength;
    for(int i=0;i<2*n;i++)
    {
        if(mp[cycle[i]]>0)
        {
            cycleStartingidx = mp[cycle[i]];
            cycleLength = i-cycleStartingidx+1;
            break;
        }
        mp[cycle[i]] = i+1;
    }

    if(k>=2*n){
   // cout<<cycleStartingidx<<"\n";
    k-=(cycleStartingidx-1);
    //cout<<cycleLength<<"\n";
    k%=cycleLength;
    //cout<<k<<"\n";
    cout<<cycle[cycleStartingidx-1+k]<<"\n";
    }
    else
    {
        cout<<cycle[k]<<"\n";
    }
    

 
 






 
#ifndef LOCAL_DEFINE
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 20244
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

#define ll long long

int main()
{
    std::string S, T;
    std::cin >> S >> T;

    int s_size = S.size();
    int t_size = T.size();
    int change_count = t_size;

    for(int i=0; i < (s_size - t_size + 1); i++) {
        int tmp_count = 0;
        for(int j=0; j < t_size; j++) {
            if(S[i + j] != T[j]) {
                tmp_count++;
            }
        }
        change_count = change_count > tmp_count ? tmp_count : change_count;
        if(change_count == 0) {
            break;
        }
    }
    std::cout << change_count << std::endl;
}

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

int main() {
  
  int n,k;
  
  cin >> n >> k;
  vector<bool> b(n);
  int d,x;
  int ans = 0;
  
  for (int i = 0;i<k;i++){
    cin >> d;
    	for (int j = 0;j<d;j++){
          cin >> x;
          b.at(x-1) = true;
        }
  }
  for(int i = 0;i<n;i++){
    if(b.at(i) == true){
    ans = ans + 1;
    }
  }
  cout << n - ans << endl;
  
  
}


Measured memory_bytes: 3632
// Problem Code: abc177_a

#include <iostream>
#include <string>

using namespace std;

string dont_be_late(int D, int T, int S) {
	return (D <= S * T) ? "Yes" : "No";
}

int main() {
	int D, T, S;
	cin >> D >> T >> S;
	cout << dont_be_late(D, T, S);
	return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>

int main(){
  int n;
  int tmp;

  scanf("%d",&n);
  tmp=n%10;
  if(tmp==3){
    printf("bon\n");
  }else if(tmp==0 || tmp==1 || tmp==6 || tmp==8){
    printf("pon\n");
  }else{
    printf("hon\n");
  }
  return 0;
}


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

using namespace std;


int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    string s;

    cin>>s;

    int strL = s.length()-1;
    int l = 0, r = strL, lr,rl;
    int flag = 0;
    lr = (strL-1)/2;
    rl = (strL+3)/2;

    //cout<<lr<<" "<<rl<<endl;

    while(1){

        if(l>lr && rl>r) break;

        if(s[l] != s[r]){
            flag = 1;
        }else if(s[l] != s[lr]){
            flag = 1;
        }else if(s[rl] != s[r]){
            flag = 1;
        }

        l++; lr--;
        rl++; r--;

        if(flag == 1) break;

    }

    if(!flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){

  string str;
  int ans =0;
  cin >> str;
  FOR(i,3) {
    if(str[i]=='1') ans++;
  }
  cout << ans fin;
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int64_t res = A.front() - 1;
  int cur = 2;
  for (int i = 1; i < N; i++) {
    if (cur == A[i]) {
      cur++;
    }
    if (cur < A[i]) {
      res += (A[i] - 1) / cur;
    }
  }
  cout << res << '\n';
  return 0;
}


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

int n;
int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}
 
int main(){
    cin >> n;
    rep(i,n) cin >> x[i] >> y[i];
    double ans = 0.0;
    rep(i,n){
        for(int j = i+1;j < n;j++) ans += dist(i,j) * 2 / n;
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
x, n = gets.chomp.split(" ").map {|c| c.to_i}
if n == 0
  puts x
  exit
end
pl = gets.chomp.split(" ").map {|c| c.to_i}

min_num = 0
min_abs = 1000


pl.sort!
(0..101).each do |pi|
  if pl.include?(pi)
    next
  end
  if min_abs > (x - pi).abs
    min_abs = (x - pi).abs
    min_num = pi
  end
end

puts min_num

Measured memory_bytes: 14396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        
        BufferedReader std = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(std.readLine());
        String str = std.readLine();
        String[] strs = str.split(" ");
        
        for(int i = strs.length-1; i >= 0; i--){
            if(i != 0){
                System.out.print(strs[i] + " ");
            } else {
                System.out.print(strs[i]);
            }
        }
        System.out.println();
    
    }

}

Measured memory_bytes: 24148
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

li n, k, a[107], dp[100007];

int main () {
    fastIO;
    cin >> n >> k;
    for(li i = 0; i < n; i ++) cin >> a[i];
    sort(a, a+n);
    for(li i = 0; i <= a[0]; i ++ ) dp[i]=1;
    for(li i = 0; i <= k; i ++) {
        if(!dp[i]) dp[i]=1;

        if(dp[i]==1)
            for(li j = 0; j < n; j ++) {
                if(i+a[j]>k) continue;
                dp[i+a[j]] = 2;
            }
    }

    if(dp[k]==2) cout << "First";
    else cout << "Second";
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long
int inf = 100000;

int main(){
  int N, ma, mb;
  cin>>N>>ma>>mb;
  int a[N], b[N], c[N];
  REP(i, N) cin>>a[i]>>b[i]>>c[i];
  int dp[401][401];
  REP(j,401)REP(k, 401){
    dp[j][k]=inf;
  }
  dp[0][0]=0;

  REP(i, N)for(int j=400; j>=a[i]; --j)for(int k=400; k>=b[i]; --k){
    dp[j][k] = min(dp[j][k], dp[j-a[i]][k-b[i]] + c[i]);
  }
  int ans=inf;
  int x=1;
  while(x*ma<401 && x*mb<401){
      ans = min(ans, dp[x*ma][x*mb]);
      ++x;
  }
  //cout<<ans<<endl;

  //REP(j,6){REP(k, 14){
  //  cout<<dp[j][k]<<" ";
  //}cout<<endl;}

  if(ans==inf) ans=-1;
  cout<<ans<<endl;

  return 0;
}


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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define sz(v) ll(v.size())

int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    rep(i,n-1){
        int count=0;
        string x="";
        string y="";
        FOR(j,i+1,n){
            y+=s[j];
        }
        rep(j,i+1){
            x+=s[j];
        }
        sort(x.begin(),x.end());
        sort(y.begin(),y.end());
        rep(j,sz(x)){
            if((y.find(x[j])!=string::npos)&&j!=0&&x[j]!=x[j-1]){
                count++;
            }else if (j==0&&(y.find(x[j])!=string::npos)){
                count++;
            }
        }
        if (ans<count){
            ans=count;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <cmath>
using namespace std;
int main(){
 int N;
 int T,A;
 int H[1000];
 int res=0;
 cin>>N>>T>>A;
 for(int i=0;i<N;++i) cin>>H[i];
 for(int i=0;i<N;++i){
 	if(abs(A - (T - H[res] * 0.006)) > abs(A - (T - H[i] * 0.006))) res = i;
 }
   cout<<res+1<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		atcode();
	}

	public static void atcode() {
		String[] info=new Scanner(System.in).nextLine().split(" ");
		Integer max=Integer.valueOf(info[0]);
		Integer sum=Integer.valueOf(info[1]);
		int count=0;
		for(int x=0;x<=max;x++) {
			for(int y=0;y<=max;y++) {
				int z=sum-x-y;
				if(z>=0&&z<=max)count++;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;

const long long MOD = 1000000007;
long long cnt[2004][2004];
long long sum[2004][2004];
int same[2004][2004];

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> s(n);
    vector<int> t(m);
    for(int i=0;i<n;i++) cin>>s[i];
    for(int i=0;i<m;i++) cin>>t[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++) {
            if (s[i] == t[j]) same[i][j] = 1;
            else same[i][j] = 0;
        }
    }
    for(int i=0;i<=n;i++) cnt[i][0] = 0LL;
    for(int j=0;j<=m;j++) cnt[0][j] = 0LL;

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i] != t[j]) {
                cnt[i+1][j+1] = 0LL;
            } else {
                cnt[i+1][j+1] = (sum[i][j] + 1LL) % MOD;
            }
            sum[i+1][j+1] = (sum[i][j+1] + sum[i+1][j] - sum[i][j] + cnt[i+1][j+1] + MOD + MOD) % MOD;
        }
    }
    cout<<(sum[n][m]+1LL)%MOD<<endl;
    return 0;
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

const int MAX_V = 666;

int N, P1, P2, M;
int d[MAX_V][MAX_V];
bool used[MAX_V];
int id[MAX_V];
int val[MAX_V];

typedef pair<int, int> P;
P dfs(int u, int c, int k){
    if(used[u]) return P(0, 0);
    used[u] = true;
    id[u] = k;
    val[u] = c;
    P res(0, 0);
    if(c == 0) res.first ++;
    if(c == 1) res.second ++;
    REP(v, M) if(d[u][v] >= 0){
        P p = dfs(v, c ^ d[u][v], k);
        res = P(res.first + p.first, res.second + p.second);
    }
    return res;
}

void add(int& x, int y){
    x = min(x + y, 2);
}

int main(){
    int N, P1, P2;
    while(cin >> N >> P1 >> P2 && !(N == 0 && P1 == 0 && P2 == 0)){
        M = P1 + P2;
        memset(d, -1, sizeof(d));
        REP(i, N){
            int x, y;
            string s;
            cin >> x >> y >> s;
            d[x - 1][y - 1] = d[y - 1][x - 1] = (s[0] == 'y' ? 0 : 1);
        }
        memset(used, 0, sizeof(used));
        int K = 0;
        vector<P> vp;
        REP(i, M) if(!used[i]){
            P p = dfs(i, 0, K++);
            vp.push_back(p);
        }

        int dp[MAX_V][MAX_V] = {};
        int back[MAX_V][MAX_V] = {};
        dp[0][0] = 1;
        for(int i = 0; i < vp.size(); i++){
            for(int j = M; j >= 0; j--){
                if(dp[i][j] >= 1){
                    add(dp[i + 1][j + vp[i].first], dp[i][j]);
                    add(dp[i + 1][j + vp[i].second], dp[i][j]);
                    back[i + 1][j + vp[i].first] = 0;
                    back[i + 1][j + vp[i].second] = 1;
                }
            }
        }
        if(dp[vp.size()][P1] == 1){
            int curr = P1;
            for(int i = vp.size() - 1; i >= 0; i--){
                if(back[i + 1][curr] == 0){
                    curr -= vp[i].first;
                }else{
                    curr -= vp[i].second;

                    for(int u = 0; u < M; u++)
                        if(id[u] == i)
                            val[u] ^= 1;
                }
            }
            for(int i = 0; i < M; i++){
                if(val[i] == 0){
                    cout << i + 1 << endl;
                }
            }
            cout << "end" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6432
#include<iostream>
#include<cstring>
#include<string>

using namespace std;

int main(void){
	int a,b;
	string str;
	string str2;
	while(cin >> str >> str2){
		int ans=0;
		for(a=0;a<str.size();a++){
			int res=0;
			string tmp= str.substr(a, str.size()-a);
			for(b=0;b<min(tmp.size(),str2.size());b++){
				if(tmp[b]==str2[b])res++;
				else ans=max(res,ans),res=0;
				if(min(tmp.size(),str2.size())-1==b)ans=max(res,ans);
			}
		}
		for(a=0;a<str2.size();a++){
			int res=0;
			string tmp= str2.substr(a, str2.size()-a);
			for(b=0;b<min(tmp.size(),str.size());b++){
				if(tmp[b]==str[b])res++;
				else ans=max(res,ans),res=0;
				if(min(tmp.size(),str.size())-1==b)ans=max(res,ans);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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


int main(){
    int n,k;
    string S;
    cin>>S;
    
    int win =0;
    for (int i = 0; i < S.length(); i++)
    {
        if(S[i]=='o'){
            win++;
        }
    }
    


    string ans;
    
    if(15-S.length()+win>=8){
        ans = "YES";
    }else{
        ans = "NO";
    }

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

Measured memory_bytes: 256
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(readline())
S = []
T = []
for i in range(n):
    s, t = readline().decode('utf-8').split()
    t = int(t)
    S.append(s)
    T.append(t)
X = readline().decode('utf-8').split()[0]

idx = S.index(X)
res = sum(T[idx+1:])

print(res)


Measured memory_bytes: 21884
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n,k;
		String str;
		char[] ch;
		char c;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		sc.nextLine();
		str = sc.nextLine();
		ch = str.toCharArray();
		c = ch[k-1];
		switch (c){
			case 'A':
				c = 'a';
			break;
			case 'B':
				c = 'b';
			break;
			case 'C':
				c = 'c';
			break;
		}
		ch[k-1] = c;

		System.out.println(String.valueOf(ch));
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> L(N+1);
  for (int i=0; i<=N; i++) {
    if (i==0) L.at(i) = 2;
    else if (i==1) L.at(i) = 1;
    else L.at(i) = L.at(i-1)+L.at(i-2);
  }
  cout << L.at(N) << endl;
}

Measured memory_bytes: 256
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextCharArray();
  var output = 1;
  for(var i = 1; i < N; i++){
    if(list[i] != list[i - 1]){
      output++;
    }
  }
  myout(output);
}


Measured memory_bytes: 34532
T,A,K=input().split()
T=int(T)
A=int(A)
K=int(K)

if T>=K:
	T=T-K
	print(T,A)
elif T<K:
	K=K-T
	T=0
	A=A-K
	if A<0:
		A=0
		print(T,A)
	else:
		print(T,A)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int l, r;
    cin >> l >> r;
    int ans = 1e9;
    for (int i = l; i <= min(r, l + 2018); i++) {
        for (int j = i + 1; j <= min(r, l + 2018); j++) {
            ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string N;
    cin >> N;
    string str(N);
    if ((str[0] == str[1] && str[1] == str[2]) || (str[1] == str[2] && str[3] == str[2])){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N,T;
cin >> N >> T;
vector<pair<int,int>> vec(N);
int mini = INF;
for (int i = 0;i < N;i++) {
    cin >> vec.at(i).first >> vec.at(i).second;
    if (vec.at(i).second <= T && vec.at(i).first < mini) {
        mini = vec.at(i).first;
    }
}
if (mini == INF) cout << "TLE" << endl;
else cout << mini << endl;


return 0;
}


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

using namespace std;

int main()
{
    int a ,m;
    bool flag=true;
    cin>>a >>m;
    char x[a][a],z[m][m];
    for(int i=0; i<a; i++)
        for(int j=0; j<a; j++)
            cin>>x[i][j];

    for(int i=0; i<m; i++)
        for(int j=0; j<m; j++)
        {
            cin>>z[i][j];
        }

    for(int i=0; i<a; i++)
    {
        for(int j=0; j<a; j++)
        {

                flag=true;
            for(int w=i,k=0; w<m+i; k++,w++)
            {
                for(int q=j,k2=0; q<m+j; k2++,q++)
                {
                    if(x[w][q]!=z[k][k2])
                        flag=false;


                }
            }
            if(flag)
                return cout<<"Yes", 0;
        }
    }



    cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


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


ll N, K;
double a[MAX*2];

ll ok(double X) {
  ll i;
  ll res=0;
  for(i=0; i<N; i++) {
    res+=(ll)(a[i]/X);
  }
  
  return res<=K;
}


int main(void) {
  ll i, j, k;
  
  cin >> N >> K;
  for(i=0; i<N; i++) cin >> a[i];
  
  double l=0, r=1e9;
  for(i=0; i<100; i++) {
    double m=(l+r)/2;
    if(ok(m)) r=m;
    else l=m;
  }
  
  pt((ll)ceil(l));
}




Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A;
  cin >> N >> A;
 
  if (A >= N) {
    cout << "Yes" << endl;
  }
  else if (N % 500 <= A){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
bool vis[45][45][45][45];
int dp[45][45][45][45];
char s[45][45];
int H,W,sum[45][45];
void Init() {
    read(H);read(W);
    for(int i = 1 ; i <= H ; ++i) scanf("%s",s[i] + 1);
}
int query(int lx,int ly,int rx,int ry) {
    return sum[rx][ry] + sum[lx - 1][ly - 1] - sum[rx][ly - 1] - sum[lx - 1][ry];
}
int dfs(int lx,int ly,int rx,int ry) {
    if(lx == 1 && ly == 1 && rx == H  && ry == W) return 0;
    if(vis[lx][ly][rx][ry]) return dp[lx][ly][rx][ry];
    int res = 100000;
    for(int i = rx + 1 ; i <= H ; ++i) {
	for(int j = ry + 1 ; j <= W ; ++j) {
	    int t = query(lx,ry + 1,rx,j) + query(rx + 1,ly,i,ry);
	    if(t >= res) break;
	    res = min(t + dfs(lx,ly,i,j),res);
	}
    }
    for(int i = rx + 1 ; i <= H ; ++i) {
	for(int j = ly - 1 ; j >= 1 ; --j) {
	    int t = query(lx,j,rx,ly - 1) + query(rx + 1,ly,i,ry);
	    if(t >= res) break;
	    res = min(t + dfs(lx,j,i,ry),res);
	}
    }
    for(int i = lx - 1 ; i >= 1 ; --i) {
	for(int j = ly - 1 ; j >= 1 ; --j) {
	    int t = query(i,ly,lx - 1,ry) + query(lx,j,rx,ly - 1);
	    if(t >= res) break;
	    res = min(t + dfs(i,j,rx,ry),res);
	}
    }
    for(int i = lx - 1 ; i >= 1 ; --i) {
	for(int j = ry + 1 ; j <= W ; ++j) {
	    int t = query(i,ly,lx - 1,ry) + query(lx,ry + 1,rx,j);
	    if(t >= res) break;
	    res = min(t + dfs(i,ly,rx,j),res);
	}
    }
    vis[lx][ly][rx][ry] = 1;
    return dp[lx][ly][rx][ry] = res;
}
void Solve() {
    pii p;
    for(int i = 1 ; i <= H ; ++i) {
	for(int j = 1 ; j <= W ; ++j) {
	    if(s[i][j] == 'P') p = mp(i,j);
	    if(s[i][j] == '#') sum[i][j]++;
	    sum[i][j] = sum[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
	}
    }
    int ans = 100000;
    for(int i = 1 ; i <= H ; ++i) {
	for(int j = 1 ; j <= W ; ++j) {
	    for(int k = i ; k <= H ; ++k) {
		for(int h = j ; h <= W ; ++h) {
		    if(p.fi >= i && p.fi <= k && p.se >= j && p.se <= h) {
			int t = query(i,j,p.fi,p.se);
			t = min(t,query(p.fi,p.se,k,h));
			t = min(t,query(i,p.se,p.fi,h));
			t = min(t,query(p.fi,j,k,p.se));
			if(t >= ans) continue;
			ans = min(t + dfs(i,j,k,h),ans);
		    }
		}
	    } 
	}
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
    return 0;
}


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

using namespace std;

int main(){
while(1){

int H,W;

cin >>H>>W;

if(H==0 && W==0) break;

for(int i=0; i<H;i++){
for(int j=0;j<W;j++){
cout<<"#";
}
cout<<endl;
}
cout<<endl;
}

return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n,d,x;
    cin>>n>>d>>x;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    int sum=0;
    rep(i,n){
        sum += 1 +(d-1)/a[i];
    }
    sum += x;
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/
ll modpow(ll a, ll b)
{
	if (b == 0)
	{
		return 1;
	}

	if (b % 2)
	{
		return a * modpow(a, b-1) % MOD;
	}
	else
	{
		ll halfB = b / 2;
		ll half = modpow(a, halfB);
		return half * half % MOD;
	}
}

ll calcComb(ll n, ll m)
{
	if (m > n-m)
	{
		return calcComb(n, n-m);
	}

	ll ansMul = 1;
	ll ansDiv = 1;

	rep(i, m)
	{
		ansMul *= (n-i);
		ansDiv *= (i+1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}

	return ansMul * modpow(ansDiv, MOD - 2) % MOD;
}

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

	ll N, M;
	
	cin >> N >> M;

	ll a[N];
	ll sum = 0;

	map<ll, ll> m;

	rep(i, N)
	{
		cin >> a[i];
		sum += a[i];

		m[sum%M]++;
	}

	map<ll,ll>::iterator it = m.begin();

	ll ret = 0;
	for(; it!=m.end(); it++)
	{
		if (it->first == 0)
		{
			ret += it->second;
		}

		if (it->second >= 2)
		{
			//ret += calcComb(it->second, 2);
			ret += (it->second-1)*it->second / 2;
		}
	}
	
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    long long int ans = 0;
    if(n%2==0)
    {
        ans = n/2;
        ans*=(n-1);
    }
    else
    {
        ans = (n-1)/2;
        ans*=n;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

struct TopologicalSort {
    int n;
    vector <set<int>> G;
    vector<bool> used;
    vector<int> indeg, p;

    TopologicalSort() {}
    TopologicalSort(int sz) : n(sz), G(n), used(n), indeg(n), p(0) {}

    void add_edge(int s, int t) {
        G[s].insert(t);
    }

    void bfs(int s) {
        queue<int> q;
        q.push(s);
        used[s] = 1;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            p.push_back(v);
            for (int u:G[v]) {
                indeg[u]--;
                if (indeg[u] == 0 && !used[u]) {
                    used[u] = 1;
                    q.push(u);
                }
            }
        }
    }

    vector<int> build() {
        fill(used.begin(), used.end(), 0);
        fill(indeg.begin(), indeg.end(), 0);

        for (int i = 0; i < n; i++) {
            for (int v:G[i]) {
                indeg[v]++;
            }
        }

        for (int i = 0; i < n; i++) {
            if (indeg[i] == 0 && !used[i]) {
                bfs(i);
            }
        }

        return p;
    }
};

int parent[100005];

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

    int N, M;
    cin >> N >> M;
    vector <int> in[N], out[N];
    TopologicalSort ts(N);
    for (int i = 0; i < N-1+M; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        ts.add_edge(s, t);
        in[t].push_back(s);
        out[s].push_back(t);
    }

    int root;
    for (int i = 0; i < N; i++) {
        if (in[i].size() == 0) {
            root = i;
            break;
        }
    }

    auto p = ts.build();

    for (int node : p) {
        for (int i = 0; i < out[node].size(); i++) {
            parent[out[node][i]] = node + 1;
        }
    }

    for (int i = 0; i < N; i++) {
        cout << parent[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 22904
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vec;
int n,len,pos;
string s;
 
vec mul(vec a,vec b){
  vec res(n*n);
  for(int i=0;i<n*n;i++)res[i]=b[a[i]];
  return res;
}
 
vec mpow(vec a,int t){
  if(t==0){
    vec res(n*n);
    for(int i=0;i<n*n;i++)res[i]=i;
    return res;
  }  
  vec res=mpow(mul(a,a),t/2);
  if(t%2==1)res=mul(res,a);
  return res;
}
 
vec calc();
 
vec getNum(){
 
  if(s[pos]=='('){
    pos++;
    vec res=calc();
    
    int num=0;
    while(pos<len&&'0'<=s[pos]&&s[pos]<='9')
      num=num*10+s[pos++]-'0';
    vec Ra= mpow(res,num);
    return Ra;
  }
  
  char ch=s[pos++];
  int num=0;
  while(pos<len&&'0'<=s[pos]&&s[pos]<='9'){
    num=num*10+s[pos]-'0';
    pos++;
  }
  
  vec res(n*n);  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int ni=i,nj=j;
      if(ch=='D'&&j+1==num){
        ni=(i+1)%n;
        nj=j;
      }else if(ch=='L'&&i+1==num){
        ni=i;
        nj=(j+n-1)%n;
      }else if(ch=='U'&&j+1==num){
        ni=(i+n-1)%n;
        nj=j;
      }else if(ch=='R'&&i+1==num){
        ni=i;
        nj=(j+1)%n;
      }
      res[i*n+j]=ni*n+nj;
    }
  }
  return res;
}
 
int C=0;
vec calc(){
  vec res=getNum();
  
  while(pos<len){
    if(s[pos]==')'){
      pos++;
      break;
    }
    vec num=getNum();
    res=mul(res,num);
  }
  return res;
}
 
int main() {
  while(cin>>n>>len) {
    cin>>s;
    pos=0;
    vec ans(n*n),ans2=calc();
    for(int i=0;i<n*n;i++){
      ans[ ans2[i]]=i;
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(j)cout<<' ';
        cout<<ans[i*n+j]+1;
      }
      cout<<endl;
    }
  }
  return 0;
}

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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_H = 1e5 + 5;
const int MAX_N = 3e3 + 5;

ll fastExpo(int base, int e) {
    ll ans = 1;
    while(e != 0) {
        if(e % 2 == 1) ans = (ll) ans * base % MOD;
        base = (ll) base * base % MOD;
        e /= 2;
    }
    return ans;
}

namespace modOp {
    int add(int a, int b, int mod = MOD) {/*return (a + b) % mod;*/  int r = a + b; if (r >= mod) r -= mod; return r;} 
    int sub(int a, int b, int mod = MOD) {/*return (a - b + mod) % mod;*/ int r = a - b; if (r < 0) r += mod; return r;}
    int mul(int a, int b, int mod = MOD) {return (ll)a * b % mod;}
    int divide(int a, int b, int mod = MOD) {return (ll)a * fastExpo(b, mod - 2) % mod;} //mod has to be a prime number
}
using namespace modOp;

int H, W, N;
pi walls[MAX_N];
int dp[MAX_N];
ll fac[2 * MAX_H], inv[2 * MAX_H];

int f(int a, int b) {
	a += b;
	if (a < 0 || b < 0 || b > a) return 0;
	return mul(fac[a], mul(inv[b], inv[a - b]));
}

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

	fac[0] = inv[0] = 1;
	for (int i = 1; i < 2 * MAX_H; ++i) {
		fac[i] = mul(fac[i - 1], i);
		inv[i] = divide(1, fac[i]);
	}

	cin >> H >> W >> N;
	for (int i = 0; i < N; ++i) {
		cin >> walls[i].ff >> walls[i].ss;
	}
	walls[N] = {H, W};

	sort(walls, walls + N + 1, [](pi a, pi b) {return a.ff + a.ss < b.ff + b.ss;});

	for (int i = 0; i <= N; ++i) {
		dp[i] = f(walls[i].ff - 1, walls[i].ss - 1);
		for (int j = 0; j < i; ++j) {
			if (walls[i].ff >= walls[j].ff && walls[i].ss >= walls[j].ss) {
				dp[i] = sub(dp[i], mul(dp[j], f(walls[i].ff - walls[j].ff, walls[i].ss - walls[j].ss)));
			}
		}
	}

	cout << dp[N] << '\n';

	return 0;
}

Measured memory_bytes: 3456