akhauriyash/Code-Regression huggingface dataset:
def examC():
    N = I()
    A = LI(); A.sort(reverse = True)
    d = defaultdict(int)
    cur = []
    ans = 0
    for i in range(N):
        d[A[i]] +=1
        if d[A[i]]==2:
            cur.append(A[i])
        elif d[A[i]]==4:
            cur.append(A[i])
        if len(cur)==2:
            ans = cur[0] * cur[1]
            break
    print(ans)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


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

int main()
{
  long long n, b, r;
  long long sum, rm;

  cin >> n >> b >> r;
  if (b+r==0) sum = 0;
  else {
    sum = b * (n / (b+r));
    rm = n % (b+r);
    if (rm > b) sum += b;
    else sum += rm;
  }
  
  cout << sum << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define size 100000
#define ll long long
using namespace std;
int grundy[size+1];
int a[size];
void init(int min)
{
    for(int i=0;i<=size;i++)
    {
        if(i>=min)
        grundy[i]=-1;
        else
        grundy[i]=0;
    }
}
int solve(int k,int n)
{
    if(k<0)
    return 1;
    if(grundy[k]!=-1)
    return grundy[k];
    int s=1;
    for(int i=0;i<n;i++)
    {
        s*=solve(k-a[i],n);
    }
    if(s==0)
    return grundy[k]=1;
    else
    return grundy[k]=0;
}

int main()
{
	int n,k;
    cin>>n>>k;
    int m=INT_MAX;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        m=min(a[i],m);
    }
    init(m);
    
    ll ans=0;
    if(n==1)
    {
    	if((k/a[0])&1)
    	cout<<"First";
    	else
    	cout<<"Second";
    	exit(0);
	}
    ans=solve(k,n);
    if(ans)
    cout<<"First";
    else
    cout<<"Second";
	return 0;
}


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

#define REP(i,n) for(int i = 0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<long, long> pl;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h;cin >> h;
    ll x = 1;
    while(x<=h)x*=2;
    cout << x-1 << endl;
 
}

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

int main() {

	//float A, B, H, M,kaku;
	int H1, M1, H2, M2, K, time,time1, time2,res;
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	H1 = H1 * 60;
	time1 = H1 + M1;

	H2 = H2 * 60;
	time2 = H2 + M2;

	time = time2 - time1;

	res = time - K;

	cout << res << endl;
	
}


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

int main(){
    string s;
    cin >> s;
    int K;
    cin >> K;
    set<string> st;
    for (int i = 1; i <= K; i++){
	for (int l = 0; l < s.size(); l++){
	    if (l+i > s.size()) break;

	    string sub = s.substr(l, i);
	    st.insert(sub);
	}
    }

    int cnt = 0;
    for (auto itr = st.begin(); itr != st.end(); itr++){
	if (cnt == K-1){
	    cout << *itr << endl;
	    break;
	}
	cnt++;
    }

    return 0;
}


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

int main()
{
	int S, h, m, s;
	cin >> S;

	h = S / 3600;
	m = (S / 60) % 60;
	s = S % 60;

	cout << h << ":" << m << ":" << s << endl;

	return 0;

}

Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

ll dp[2][2019];
int main(){
  string S; cin >> S;
  ll ans = 0;
  rep(i,sz(S)){
    rep(j,2019){
      dp[(i+1)%2][(j*10+(int)(S[i]-'0'))%2019] = dp[i%2][j];
    }
    dp[(i+1)%2][S[i]-'0']++;
    ans += dp[(i+1)%2][0];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3760
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	String s;
	public void solve() {
		s = next();
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < s.length();i++){
			char c = s.charAt(i);
			if(c == '0'){
				sb.append(c);
			}else if(c == '1'){
				sb.append(c);
			}else{
				if(sb.length() > 0)sb.deleteCharAt(sb.length() - 1);
			}
		}
		out.println(sb.toString());
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 8020
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#define int long long

using namespace std;

int a, b, c, d;

int f(int x, int y) {
  return x / y;
}

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

int lcm(int a, int b) {
  return a / gcd(a, b) * b;
}

int32_t main() {
  cin >> a >> b >> c >> d;
  int withc = f(b, c) - f(a - 1, c);
  int withd = f(b, d) - f(a - 1, d);
  int gc = lcm(c, d);
  int withboth = f(b, gc) - f(a - 1, gc);
  int ans = b - a + 1;
  ans -= withc;
  ans -= withd;
  ans += withboth;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

n = int(input())
A = list(map(int, input().split()))
count = Counter(A)
q = int(input())
B = [list(map(int, input().split())) for i in range(q)]

s = sum(A)
for b, c in B:
    num = count[b]
    s += (c - b)*num
    count[c] += num
    count[b] = 0
    print(s)


Measured memory_bytes: 104560
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	while (true) {
		int n, a, b, c, x;
		cin >> n >> a >> b >> c >> x;
		if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0)break;

		VI y(101);
		rep(i, n)cin >> y[i];

		int i = 0, ans = -1;
		rep(loop, 10001) {
			if (y[i] == x)i++;
			x = (a*x + b) % c;
			if (i == n) { ans = loop; break; }
		}
		cout << ans << endl;

	}
}


Measured memory_bytes: 2968
// a, b, c ---> (a + b) / 2, (b + c) / 2,  (a + c) / 2
//不妨假定 a < b < c，令x = b - a, y = c - a, 三个物品同时均减去 a 对答案没有影响 
//上述变换等价于 0, x, y -> (x + y) / 2, x / 2, y / 2  --->  0, y / 2, (y - x) / 2 
//这样最大值 - 最小值 由 y - 0 -> y / 2 - 0缩小了一半
//当最大值 = 最小值的时候 显然可以循环下去 因此操作log次必然可以得到答案

#include<bits/stdc++.h>
using namespace std;

int main(){
	int nA, nB, nC, A, B, C, ans = 0;;
	
	scanf("%d%d%d", &A, &B, &C);
	
	while(true){
		if((A & 1) || (B & 1) || (C & 1)){
			printf("%d", ans);
			break;
		}
		if(A == B && B == C){
			printf("-1");
			break;
		}
		
		++ans;
		nA = (B + C) / 2;
		nB = (A + C) / 2;
		nC = (A + B) / 2;
		A = nA, B = nB, C = nC; 
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
    char moji[2000001];
    int i,sum;

    scanf("%s",moji);
    int len = strlen(moji);//桁数の取得
    sum = 0;

    for(i = 0; i<len ; i++){
        sum += moji[i] - '0'; //文字を数字に変換している
    }

    puts(sum%9==0?"Yes":"No");

return 0;
    
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

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

  std::string S;
  std::cin >> S;

  for(int i=0;i<3;++i){
      if(S[i] == '7'){
          std::cout << "Yes" << std::endl;
          return 0;
      }
  }

  std::cout << "No" << std::endl;
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int M = sc.nextInt();
	    sc.close();
	    
	    double ans = (1900*M+100*(N-M))*Math.pow(2, M);
	    System.out.println((int) (ans));
	}
}


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

int main() {
  // int A, B, C, D, E;
  // cin >> A >> B >> C >> D >> E;
  int TIMES[5];
  for (int i = 0; i < 5; ++i) {
    cin >> TIMES[i];
  }
  int min_idx;
  int min = 10;
  for (int i = 0; i < 5; ++i) {
    if (TIMES[i] % 10 <= min && TIMES[i] % 10 != 0) {
      min_idx = i;
      min = TIMES[i] % 10;
    }
  }
  int sum = 0;
  for (int i = 0; i < 5; ++i) {
    if (i == min_idx || TIMES[i] % 10 == 0) {
      continue;
    }
    TIMES[i] += (10 - TIMES[i] % 10);
  }
  for (int i = 0; i < 5; ++i) {
    sum += TIMES[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];

        for (int i = 0; i < n; i++) {
            p[i] = s.nextInt();
        }
        for (int i = 0; i < n; i++) {
            q[i] = s.nextInt();
        }
        int rank1 = findRank(p,n);

        int rank2 = findRank(q,n);
        System.out.println(Math.abs(rank1-rank2));

    }
    static int findRank(int [] array, int length){
        int factorial = 1;
        for(int i = 2; i<=length; i++){
            factorial *= i;
        }
        int rc;
        int m = factorial;
        int rank = 1;
        for(int i = 0; i<length; i++){
            m = m/(length-i);
            rc = 0;
            for(int j = i+1; j<= length-1; j++){
                if(array[j] < array[i]){
                    rc++;
                }
            }
            rank = rank + (rc * m);
        }
        return rank;
    }
}


Measured memory_bytes: 21844
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}

uint32_t nextpint(void){
	char c=getchar();
	while(c<'0'||'9'<c) c=getchar();
	uint_fast32_t x=0;
	while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); }
	return x;
}

int m[500][500];
int s[250000][4], S=0;
int main(void){
	int h=nextpint();
	int w=nextpint();
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			m[i][j]=nextpint();
		}
	}
	for(int i=0; i<h-1; i++){
		for(int j=0; j<w; j++){
			if(m[i][j]%2!=0){
				m[i+1][j]++;
				s[S][0]=i;
				s[S][1]=j;
				s[S][2]=i+1;
				s[S][3]=j;
				S++;
			}
		}
	}
		int i=h-1;
		for(int j=0; j<w-1; j++){
			if(m[i][j]%2!=0){
				m[i][j+1]++;
				s[S][0]=i;
				s[S][1]=j;
				s[S][2]=i;
				s[S][3]=j+1;
				S++;
			}
		}
	printf("%d\n", S);
	for(int i=0; i<S; i++){
		printf("%d %d %d %d\n", s[i][0]+1, s[i][1]+1, s[i][2]+1, s[i][3]+1);
	}
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 2000009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e14 + 9;
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll fastpow(ll a, ll b){
    ll calc=1;
    for(;b>=1LL;b/=2LL){
        if((b&1LL))calc=mult(calc,a);
        a=mult(a,a);
    }
    return calc;
}
ll soma(ll a,ll b){
    if(a+b>MOD)return a+b-MOD;
    else return a+b;
}
ll subt(ll a,ll b){
    if(a-b<0)return a-b+MOD;
    else return a-b;
}
ll fact[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    fact[0]=1;
    rep(i,1,maxn)fact[i] = mult(i,fact[i-1]);
    ll k;
    string s;
    cin>>k>>s;
    ll n = sz(s)+k;
    ll tir = 0;
    rep(i,0,sz(s)){
        tir = soma(tir, mult(fastpow(25,n-i),mult(fact[n],fastpow(mult(fact[i],fact[n-i]),MOD-2))));
    }
    cout<<subt(fastpow(26,n),tir)<<"\n";
    return 0;  
}   

Measured memory_bytes: 19852
N=int(input())
s=[input() for _ in range(N)]
def checkAB(si):
  cnt=0
  for i in range(len(si)-1):
    if si[i]=='A' and si[i+1]=='B':cnt+=1
  return cnt

ABin=sum([checkAB(si) for si in s])
Aend=sum([si[len(si)-1]=='A' for si in s])
Bstart=sum([si[0]=='B' for si in s])
BstrA=sum([si[0]=='B' and si[len(si)-1]=='A' for si in s])
#print(ABin,Aend,Bstart)
if BstrA==Aend and BstrA==Bstart and BstrA>0:
  ans=ABin+BstrA-1
else:
  ans=ABin+min(N-1,Aend,Bstart)
print(ans)


Measured memory_bytes: 3700
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 401
#define M 100010
#define N2 (N/64+1)
ll n, m, x[M], y[M], k[N][N];
ull k2[N][N2];
int main(){
	cin>>n>>m;
	rep(i, m){
		cin>>x[i]>>y[i]; x[i]--; y[i]--;
	}
	reverse(x, x+m);
	reverse(y, y+m);
	rep(i, n){
		k[i][i] = 1;
		rep(j, m){
			if(k[i][x[j]]&&k[i][y[j]]) {k[i][i] = 2; break;}
			else if(k[i][x[j]]) k[i][y[j]] = 1;
			else if(k[i][y[j]]) k[i][x[j]] = 1;
		}
		if(k[i][i]==2){
			mset(k2[i], -1);
			continue;
		}
		rep(j, n) if(k[i][j]) k2[i][j/64] |= 1ull<<(j%64);
	}
	ll res = 0;
	rep(i, n) rep(j, i){
		int r = 1;
		rep(l, n/64+1){
			if(k2[i][l]&k2[j][l]){
				r = 0;
				break;
			}
		}
		res += r;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>

using namespace std;

 
int main() {
    int H, W;
    cin >> H >> W;
    vector<string> masu(H);
    for(int i=0 ; i<H ; i++){
        cin >> masu.at(i);
    }

    for(int i=0 ; i<H ; i++){
        for(int j=0 ; j<W ; j++){
            if(masu.at(i).at(j) == '.'){
                int mine = 0;
                for(int k=i-1 ; k<i+2 ; k++){
                    for(int l=j-1 ; l<j+2 ; l++){
                        if(k<0 || l<0 || k>H-1 || l>W-1 || (k==i && l==j)){continue;}
                        if(masu.at(k).at(l) == '#'){mine++;}
                    }
                }
                cout << mine;
            }else{
                cout << '#';
            }
        }
        cout << endl;
    }
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

bool isPrime(int n) {
    bool flag = true;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            flag = false;
            break;
        }
    }
    return flag;
}

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

    vector<int> prime5;

    repd(i, 11, 55555) {
        if (isPrime(i)) {
            if (i % 5 == 1) {
                prime5.push_back(i);
            }
        }
    }

    rep(i, N - 1) {
        cout << prime5[i] << " ";
    }
    cout << prime5[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int i;
  int a[n];
  for(i=0;i<n;++i){
    cin >> a[i];
  }
  int b[n];
  for(i=0;i<n;++i){
    cin >> b[i];
  }
  int c[n-1];
  for(i=0;i<n-1;++i){
    cin >> c[i];
  }

  int m=0;
  for(i=0;i<n;++i){
    m=m+b[i];
    if(a[i+1]==a[i]+1){
      m=m+c[a[i]-1];
    }
  }
  
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

#include<bits/stdc++.h>
using namespace std;

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl;
#define nl cout << endl
#define hello cout << "hello" << endl;
#define sp(x) fixed << setprecision(x)
#define re return

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s) 
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n) 
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}
void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LONG_MIN,minl = LONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int x;
	cin >> x;
	ll k = 1;
	while((k*x)%360 != 0)
	{
		k++;
	}
	W(k);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3604
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
//暴力。复杂度我觉得ok
int n,x,sn=0; ll st[SZ];
map<ll,ll> ms[SZ]; ll qz[SZ];
int main()
{
	scanf("%d%d",&n,&x); st[++sn]=n;
	while(x--)
	{
		ll q; scanf("%lld",&q);
		while(sn&&st[sn]>=q) --sn;
		st[++sn]=q;
	}
	int N=n; n=st[1];
	st[0]=n; ms[sn-1][st[sn]]=1;
	for(int i=sn-1;i>=1;--i)
	{
		for(auto j:ms[i])
		{
			if(j.fi<=n) qz[j.fi]+=j.se;
			else
			{
				ms[i-1][st[i]]+=j.fi/st[i]*j.se;
				ll p=j.fi%st[i];
				if(p<=n) qz[p]+=j.se;
				else
				{ 
					int g=lower_bound(st,st+sn+1,p)-st-1;
					ms[g][p]+=j.se;
				}
			}
		}
	}
	for(auto j:ms[0]) qz[j.fi]+=j.se; n=N;
	for(int i=n;i>=1;--i) qz[i]+=qz[i+1];
	for(int i=1;i<=n;++i) printf("%lld\n",qz[i]);
}


Measured memory_bytes: 57984
#include <bits/stdc++.h>
     
#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()
     
using namespace std;
using ll = long long;
using P = pair<int, int>;
     
template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }
     
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main(){
  int N; cin >> N;
  int min = INF, max = 0;
  REP( i, N ){
    int a; cin >> a;
    chmin( min, a );
    chmax( max, a );
  }

  cout << max - min << endl;
}


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

#define _GLIBCXX_DEBAC
using namespace std;


int main() {
	int n;
	string s;
	cin >> n>>s;
	for (int i = 0; i < s.size(); i++) {
		s[i] = (s[i] - 'A' + n) % 26 + 'A';
	}
	cout << s << endl;
		return 0;
}









Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    n=n%26;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        s[i]=(s[i]+char(n));
        if(s[i]>'Z')
            s[i]=s[i]-char(26);
        cout<<s[i];
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    int n,k;
    cin>>n>>k;
    ll s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    ll ans=0;
    for(int i=0;i<n-k+1;i++){
        ll p=0;
        p=(s[i+k-1]-s[i])+min(abs(s[i+k-1]),abs(s[i]));
        if(ans==0)ans=p;
        ans=min(ans,p);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int x;
  cin >> x;
  if (x < 1200)
    cout << "ABC" << endl;
  else
    cout << "ARC" << endl;
}


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

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;

#define MEM(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        cout << A[i] << " ";
    }
    cout << endl;
}

LL solve() {
    int n;
    cin >> n;

    LL res = 0;

    vector<int> A(n, 0);

    REP(i, n) {
        cin >> A[i];
        if ((i + 1) % 2 == 1 && (A[i] % 2 == 1)) {
            res++;
        }
    }


    return res;
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();

    int t = 1;

    // cin >> t;

    for (int _ = t; _ > 0; _--) {
        cout << solve() << endl;
    }

    return 0;
}



Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define foe(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
#ifdef flukehn
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
const int N=2e5+11,mo=1e9+7;
int fpow(int a,int b){
	int r=1;
	for(;b;b>>=1,a=1ll*a*a%mo)
		if(b&1)r=1ll*r*a%mo;
	return r;
}
int inv(int x){return fpow(x,mo-2);}
int jc[N+2],jcv[N+2];
int C(int a,int b){
	if(a<b)return 0;
	return 1ll*jc[a]*jcv[b]%mo*jcv[a-b]%mo;
}
int A[N],B[N];
int main(){
#ifdef flukehn
	freopen("a.in","r",stdin);
#endif
	ios::sync_with_stdio(0);
	jc[0]=1;
	rep(i,1,N)jc[i]=1ll*jc[i-1]*i%mo;
	jcv[N]=inv(jc[N]);
	per(i,1,N)jcv[i-1]=1ll*jcv[i]*i%mo;
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	int p=inv(a+b),pa=1ll*a*p%mo,pb=1ll*b*p%mo;
	A[0]=1;rep(i,1,n)A[i]=1ll*A[i-1]*pa%mo;
	B[0]=1;rep(i,1,n)B[i]=1ll*B[i-1]*pb%mo;
	int ans=0;
	rep(i,0,n-1){
		ans=(ans+1ll*C(n+i-1,n-1)*A[n]%mo*B[i]%mo*(n+i))%mo;
	}
	rep(i,0,n-1){
		ans=(ans+1ll*C(n+i-1,n-1)*A[i]%mo*B[n]%mo*(n+i))%mo;
	}
	//cerr<<ans<<endl;
	ans=100ll*ans%mo*p%mo;
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
my @seisu,@seisu_no_kachi;

#入力1行目読み込む
my $input=<STDIN>;
chomp ($input);
my ($n, $k)=split(/ /,$input);
#残りの行読み込む
foreach (1..$n){
  chomp ($input=<STDIN>);
  my ($a, $b)=split(/ /,$input);
  push @seisu,$a;
  push @seisu_no_kachi, $b;
}
#print "$_\n"for(@seisu);
#print $seisu[3];


#my $keta; #$kの桁数
#for(0..30){
#	if (0 >= ($k>>$_)){
#		$keta=$_;
#		last;
#	}
#}

my @bitwiseor;  
	#買った整数たちの論理和が、K以下となる。
	#その様な論理和として正解となり得る値を、@bitwiseorに用意する。
for my $i(0..30){
	if ($k & (1 << $i)){ # $kの、下から（$i+1）桁目が立っている。

		my $tmp=$k; #@bitwiseor に入れることができる値を計算します。
		$tmp= $k & ~(1<<$i);					 # 下から（$i+1）桁目を0に
		$tmp|=(1<<$_) foreach(0..($i-1));        # 下から$i桁目までを１で埋める
		push @bitwiseor, $tmp
	}
}
push @bitwiseor,$k;		#  K自信も含める
#printf("%08b\n", $_) foreach(@bitwiseor);
 

my $goukei=0;
foreach my $b(@bitwiseor)
{
	my $goukei_tmp=0;
	for my $j(0..($n-1)){
		unless(fukumarenai($b, $seisu[$j])){
			$goukei_tmp+=$seisu_no_kachi[$j];
		}
	}

	 $goukei=$goukei_tmp if ($goukei < $goukei_tmp) ; 
}


#$aに$bが含まれない場合TRUE
sub fukumarenai{
	my ($a, $b)=@_;
	return ($a^($a|$b));
}

print $goukei;




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

int main() {
	int n,a,s1res,s2res,result;
	string s1,s2,s;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> s1 >> s2;
		s1res = s2res = result = 0;
		for(int j = 0;j < s1.size();j++){
			a = 1;
			if(s1[j] == '2'){
			a = 2;
			j++;
			}
			else if(s1[j] == '3'){
			a = 3;
			j++;
			}
			else if(s1[j] == '4'){
			a = 4;
			j++;
			}
			else if(s1[j] == '5'){
			a = 5;
			j++;
			}
			else if(s1[j] == '6'){
			a = 6;
			j++;
			}
			else if(s1[j] == '7'){
			a = 7;
			j++;
			}
			else if(s1[j] == '8'){
			a = 8;
			j++;
			}
			else if(s1[j] == '9'){
			a = 9;
			j++;
			}
			if(s1[j] == 'm'){
			s1res += a * 1000;
			}
			if(s1[j] == 'c'){
			s1res += a * 100;
			}
			if(s1[j] == 'x'){
			s1res += a * 10;
			}
			if(s1[j] == 'i'){
			s1res += a;
			}
		}
		for(int j = 0;j < s2.size();j++){
			a = 1;
			if(s2[j] == '2'){
			a = 2;
			j++;
			}
			else if(s2[j] == '3'){
			a = 3;
			j++;
			}
			else if(s2[j] == '4'){
			a = 4;
			j++;
			}
			else if(s2[j] == '5'){
			a = 5;
			j++;
			}
			else if(s2[j] == '6'){
			a = 6;
			j++;
			}
			else if(s2[j] == '7'){
			a = 7;
			j++;
			}
			else if(s2[j] == '8'){
			a = 8;
			j++;
			}
			else if(s2[j] == '9'){
			a = 9;
			j++;
			}
			if(s2[j] == 'm'){
			s2res += a * 1000;
			}
			if(s2[j] == 'c'){
			s2res += a * 100;
			}
			if(s2[j] == 'x'){
			s2res += a * 10;
			}
			if(s2[j] == 'i'){
			s2res += a;
			}
		}
		result = s1res + s2res;
		if(result >= 1000){
			a = result;
			a /= 1000;
			if(a == 1)cout << "m";
			else cout << a << "m";
			result = result - (a * 1000);
		}
		if(result >= 100){
			a = result;
			a /= 100;
			if(a == 1)cout << "c";
			else cout << a << "c";
			result = result - (a * 100);
		}
		if(result >= 10){
			a = result;
			a /= 10;
			if(a == 1)cout << "x";
			else cout << a << "x";
			result = result - (a * 10);
		}
		if(result >= 1 && result < 10){
			if(result == 1)cout << "i";
			else cout << result << "i";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
<?php
while ($line = fgets(STDIN)) {
   $s[] = trim($line);
}
$n = 0;
//var_dump($s);
$arr = explode(" ", trim($s[0]));
$people = $arr[0];

if($arr[1] == 0){
echo $people;
exit;
}
if($people == 0){
echo $people;
exit;
}

//echo "people: {$people}\n";
$p = array();
for($i = 1;$i<=$people;$i++){
$p[$i] = 0;
//echo " ループだよ p[{$i}]".$p[$i]."\n";
}

//var_dump($p);

$t = 0;
foreach($s as $key => $v){
$t++;
if($key < 2) continue;
$arr = explode(" ", trim($v));
$cnt = count($arr);
//echo "cnt:$cnt\n";

if(($t % 2) == 1){
//echo "2の倍数 お菓子をもらえる人が何番目\n";
foreach($arr as $value){
//echo "value:$value \n";
$p[$value] += 1;
//echo "現在のp[value]は".$p[$value]."\n";
}
}// else
else{
//echo "2の倍数以外";

}//else t


}
//echo "n:$n";

//print_r($arr);

//echo "pの中身";
//print_r($p);

for($x=1;$x<=$people;$x++){
//echo "x: {$x} p[{$x}]".$p[$x]."\n";
if($p[$x] == 0){
$n++;
}

}

//echo "現在お菓子もっていない人は{$n}人です。全部で{$people}人います\n";



echo $n;

?>

Measured memory_bytes: 16036
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os, pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 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 _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s):
    if 'LOCAL' in os.environ:
        print(s)

def main():
    global AB, PX, T
    if 'BIG' in os.environ:
        N = 2* 10** 5
        Q = 2 * 10 ** 5
        AB = [[i, i + 1] for i in range(1, N)]
        PX = [[i, 10] for i in range(Q)]
    else:
        N, Q = LI()
        #  AB = []
        T = [[] for _ in range(N+1)]
        PX = [0] * (N+1)
        for i in range(N-1):
            a, b = LI()
            #  AB += (a, b)
            T[a].append(b)
            T[b].append(a)

        for i in range(Q):
            p, x = LI()
            PX[p] += x
        dfs(1, -1)
        print(' '.join(map(lambda x: str(x), PX[1:])))
        #  for i in PX[1:]:
        #      print(i, end=' ')
        #  ans = [0 for _ in range(N)]

def dfs(parent, parent_parent):
    for node in T[parent]:
        if node != parent_parent:
            PX[node] += PX[parent]
            dfs(node, parent)

if __name__ == '__main__':
    main()



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

typedef long long ll;

ll n, k, low, up;

int main(){
    cin >> n >> k;
	low = k - k / 2;
	up = k / 2;
	for(ll i = 1; i <= low; i++){
		cout << i << " " << low * 2 - i + 1 << '\n';
	}
	for(ll i = 1; i <= up; i++){
		cout << low * 2 + i << " " << low * 2 + up * 2 - i + 2 << '\n';
	}
}

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

int main() {
  int N, Sum=0, cnt=1, A;
  cin >> N;
  rep(i, N){
    cin >> A;
    if(A!=cnt) Sum++;
    else cnt++;
  }
  if(Sum!=N) cout << Sum << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String A = sc.next();
        String B = sc.next();
        StringBuffer bf = new StringBuffer();
        //ここまで入力

        for(int i=0; i<A.length(); i++){
            bf.append(A.charAt(i));
            bf.append(B.charAt(i));
        }

        System.out.println(bf);
    }
}

Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<utility>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<deque>
#include<cctype>
using namespace std;
int main() 
{
	int A,B;
	cin>>A>>B;
	int sum=A+B;
	if(sum==0)
	{
		cout<<"Impossible";
	}
	else if(A==0)
	{
		cout<<"Impossible";
	}
	else if(B==0)
	{
		cout<<"Impossible";
	}
	else if(sum%3==0)
	{
		cout<<"Possible";
	}
	else if(A%3==0)
	{
		cout<<"Possible";
	}
	else if(B%3==0)
	{
		cout<<"Possible";
	}
	else
	{
		cout<<"Impossible";
	}
    return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n;
	cin>>n;
	vector <long long int> a;
	for(long long int i=0;i<n;i++){
		long long int x;
		cin>>x;
		a.push_back(x);
	}
	long long int count=0;
	for(long long int j=1;j<a.size();j++){
		if(a[j]<a[j-1]){
			count=count+abs(a[j]-a[j-1]);
			a[j]=a[j-1];
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 5332
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

int main()
{
    double a, b, x, ans;
    const double PI = acos(-1.0);
    cin >> a >> b >> x;

    x /= a;

    if (x > a * b / 2) {
        ans = atan2(2 * (a * b - x), a * a);
        ans = ans * 180 / PI;
    }
    else {
        ans = atan2(b * b, 2 * x);
        ans = ans * 180 /PI;
    }

    printf("%.8lf\n", ans);
    return 0;
}

Measured memory_bytes: 384
import sys,collections as cl
import collections
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

n,m = m()

a = l()

aa = [a[0]]
aaa = []
for i in range(n-1):
	aa.append(aa[-1]+a[i+1])

for i in range(n):
	aaa.append(aa[i]%m)

k = collections.Counter()

for i in aaa:
	k[i] += 1

ans = 0
for i in range(n):
	if aaa[i] != 0:
		ans += max(k[aaa[i]]-1,0)
		k[aaa[i]] = k[aaa[i]]-1
	else:
		ans += k[aaa[i]]
		k[aaa[i]] -= 1
print(ans)

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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

ll gcd(ll a, ll b){
  if(a==1 || b==1)return 1;
  if (a < b)swap(a,b);
  
  return b ? gcd(b, a % b) : a;
}

int main(){
  int k;cin>>k;
  ll result = 0;
  rep1(a, k)rep1(b,k)rep1(c,k){
    int ab = gcd(a, b);
    result += gcd(ab, c);
  }

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
	int a,b,c,d,e,t=0;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a<0&&b>0){
		t-=a*c;
		t+=d;
		t+=b*e;
	}
	else{
		t+=(b-a)*e;
	}
	printf("%d\n",t);
	return 0;
}

Measured memory_bytes: 2720
#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long
#define ld long double

int main()
{
  int L;
  cin>>L;
  ld a=(ld)L/3.0L;
  cout<<fixed<<setprecision(16);
  cout<<a*a*a<<endl;

  return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn min (a: &i64, b: &i64)-> i64{
    if *a <= 0i64 {*b}
    else if *b <= 0i64  {*a}
    else if *a < *b {*a}
    else {*b}
}

fn abs (a: &i64, b: &i64) -> i64{
    if *a - *b <= 0 {*b - *a} else {*a - *b}
}

fn main(){
    input!{
        l: [u64; 3]
    }
    print!("{} {} {}", l[2], l[0], l[1]);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>
using namespace std;
int main(void){
    int a,b;
    int h,w;
    int ans;
    cin>>a>>b>>h>>w;
    ans=a*b-h*b-(a-h)*w;
    cout<<ans<<endl;
}

Measured memory_bytes: 504
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.PriorityQueue;
import java.math.BigInteger;
    
public class Main{

static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE/2;
static final long LINF=Long.MAX_VALUE/2;
static int L,A,B,C,D;

public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
L=ir.nextInt();
A=ir.nextInt();
B=ir.nextInt();
C=ir.nextInt();
D=ir.nextInt();
A=(A%C==0)?A/C:A/C+1;
B=(B%D==0)?B/D:B/D+1;
out.println(L-Math.max(A,B));
out.flush();
}

static class InputReader {
private InputStream in;
private byte[] buffer=new byte[1024];
private int curbuf;
private int lenbuf;

public InputReader(InputStream in) {this.in=in;}
  
public int readByte() {
if(lenbuf==-1) throw new InputMismatchException();
if(curbuf>=lenbuf){
curbuf= 0;
try{
lenbuf=in.read(buffer);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(lenbuf<=0)
return -1;
}
return buffer[curbuf++];
}

public boolean isSpaceChar(int c){return !(c>=33&&c<=126);}

private int skip() {int b; while((b = readByte())!=-1&&isSpaceChar(b)); return b;}

public String next() {
int b=skip();
StringBuilder sb=new StringBuilder();
while(!isSpaceChar(b)){
sb.appendCodePoint(b);
b=readByte();
}
return sb.toString();
}
 
public int nextInt() {
int c=readByte();
while (isSpaceChar(c)) c=readByte();
boolean minus=false;
if (c=='-') {
minus=true;
c=readByte();
}
int res=0;
do{
if(c<'0'||c>'9') throw new InputMismatchException();
res=res*10+c-'0';
c=readByte();
}while(!isSpaceChar(c));
return (minus)?-res:res;
}

public long nextLong() {
int c=readByte();
while (isSpaceChar(c)) c=readByte();
boolean minus=false;
if (c=='-') {
minus=true;
c=readByte();
}
long res = 0;
do{
if(c<'0'||c>'9') throw new InputMismatchException();
res=res*10+c-'0';
c=readByte();
}while(!isSpaceChar(c));
return (minus)?-res:res;
}

public int[] toIntArray(int n){
int[] a=new int[n];
for(int i=0;i<n;i++) a[i]=nextInt();
return a;
}
}
}

Measured memory_bytes: 17052
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int k, x;

int main() {
	cin >> k >> x;
	
	
	int rc = k*2-1;
	rep(i, rc) {
		cout << x - (k - 1)+i<<" ";
	}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from bisect import bisect_left

# 区間更新 1点取得
class SegmentTree:
    def __init__(self, N):
        tmp = 1
        while tmp < N:
            tmp <<= 1
        # self.N : 完全二分木の葉の数(N以上の最小の2べき)
        self.N = tmp
        # 2*self.N - 1 : 完全二分木のノード数
        # 1-indexedで管理するので1プラス
        self.data = [float('inf') for _ in range(2*self.N)]

    # [l, r)
    # 入力は0-indexedなので注意
    def update(self, l, r, x):
        L = l + self.N
        R = r + self.N
        while L < R:
            if L & 1:
                self.data[L] = min([self.data[L], x])
                L += 1
            if R & 1:
                R -= 1
                self.data[R] = min([self.data[R], x])
            L >>= 1
            R >>= 1

    def query(self, k):
        k += self.N
        res = self.data[k]
        while k != 1:
            k >>= 1
            res = min(res, self.data[k])
        return res



def main():
    N, Q = map(int, input().split())
    road = []
    for _ in range(N):
        S, T, X = map(int, input().split())
        road.append((S,T,X))

    D = [int(input()) for _ in range(Q)]

    st = SegmentTree(Q)
    for S, T, X in road:
        l = bisect_left(D, S - X)
        r = bisect_left(D, T - X)
        st.update(l, r, X)

    for q in range(Q):
        ans = st.query(q)
        if ans == float('inf'):
            print(-1)
        else:
            print(ans)

if __name__ == "__main__":
    main()

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


int main()
{
    int n;
    int data;

    while(1){
        scanf("%d", &n);
        if(n==0){
            break;
        }
        else{
            double d1=0, d2=0;
            double var=0;
            for(int i=0; i< n; i++){
                scanf("%d", &data);
                d1 += data*data;
                d2 += data; 
            }
            var = d1/n - d2/n*d2/n;
            printf("%lf\n", sqrt(var));
        }
    }


    return 0;
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

ll n, m, q;
vll as, bs, cs, ds;
ll ans = 0;

void dfs(vll lst, ll v, ll d) {
  if (d == n) {
    ll score = 0;
    rep(i, q) {
      if (lst[bs[i]-1] - lst[as[i]-1] == cs[i]) score += ds[i];
    }
    chmax(ans, score);
  } else {
    for (ll i = v; i <= m; i++) {
      lst.push_back(i);
      dfs(lst, i, d + 1);
      lst.pop_back();
    }
  }
  return;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  cin >> n >> m >> q;

  as.resize(q);
  bs.resize(q);
  cs.resize(q);
  ds.resize(q);
  rep(i, q) cin >> as[i] >> bs[i] >> cs[i] >> ds[i];

  vll lst(0);
  dfs(lst, 1, 0);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3664
use proconio::*;

fn run() {
    input! {
        n: usize,
        k: u64,
        a: [u64; n],
    }
    let mut ng = 0;
    let mut ok = 1_000_000_000;
    while ok - ng > 1 {
        let mid = (ok + ng) / 2;
        let mut cnt = 0;
        for &a in a.iter() {
            cnt += (a - 1) / mid;
        }
        if cnt <= k {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ok);
}

fn main() {
    run();
}

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

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  H = readInts()
  m = 0
  ans = 0
  for h in H:
    if h >= m:
      ans += 1
      m = h
  print(ans)

if __name__ == "__main__":
  main()


Measured memory_bytes: 2940