akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			int n = sc.nextInt();
			int[] a = new int[n];
			HashSet<Integer> h = new HashSet<Integer>();
			
			for(int i=0;i<n;i++) {
				a[i] = sc.nextInt();
			}
			
			Arrays.sort(a);
			int ret = n;
			
			for(int i=0;i<n;i++) {
				if(i<n-1) {
					if((a[i]==a[i+1])) {
						ret--;
						for(int j=1;j*a[i]<=a[n-1];j++) {
							h.add(j*a[i]);
						}
						continue;
					}
				}
				
				
				if(!h.contains(a[i])) {
					for(int j=1;j*a[i]<=a[n-1];j++) {
						h.add(j*a[i]);
					}
				}else {
					ret--;
				}
			}
			
			
			System.out.println(ret);
		}
	}


Measured memory_bytes: 123988
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return a/g*b;
}
signed main(){
  ll n,lc=1;
  cin >> n;
  ll t[n];
  for(int i=0;i<n;i++){
    cin >> t[i];
    lc = lcm(lc,t[i]);
  }
  cout << lc << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <list>

using namespace std;

#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

const int MAXN = 3013;
int dp[MAXN][MAXN];

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    string s, t; cin >> s >> t;

    for(int i = 1; i <= s.length(); ++i){
        for(int j = 1; j <= t.length(); ++j){
            if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    list<char> q;
    int i = s.length(), j = t.length();
    
    while(i > 0 and j > 0){
        if(dp[i][j] == 0) break;
        if(s[i-1] == t[j-1]){ q.push_front(s[i-1]); i--; j--; continue; }

        if(dp[i-1][j] >= dp[i][j-1]) i--;
        else j--;
    }

    for(auto itr = q.begin(); itr != q.end(); ++itr) cout << *itr;
    cout << endl;

    return 0;
}

//cikisir



Measured memory_bytes: 35712
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll N;
    cin >> N;
    ll ans = N - 1;
    for(ll i = 1; i * i <= N; i++){
        if(N % i)continue;
        chmin(ans, i + N / i - 2);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if(n == 1 || n == 2 || n == 3 || n == 5 || n == 6 || n == 9 || n == 10 || n == 13 || n == 17) {
		cout << "No" << endl;
	}
	else{
		cout<< "Yes" <<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int[] cs1 = new int[n];
        int[] cs2 = new int[n];

        for (int i = 1; i < n-1; i++) {
            if (s.charAt(i-1) == 'W') {
                cs1[i]++;
            }
            cs1[i+1] = cs1[i];

            if (s.charAt(n-i) == 'E') {
                cs2[n-i-1]++;
            }
            cs2[n-i-2] = cs2[n-i-1];
        }

        int min = n - 1;
        for (int i = 0; i < n; i++) {
            min = Math.min(min, cs1[i] + cs2[i]);
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 31636
# -*- coding: utf-8 -*-
from itertools import product
from collections import defaultdict
def inpl(): return list(map(int, input().split()))

X = [0]*6
for i in range(6):
    X[i] = int(input())
a, b, c, d, e, k = X

for l, r in product(X[:5], repeat=2):
    if abs(l-r) > k:
        print(":(")
        break
else:
    print("Yay!")


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n+1);
    for (auto &&i : v) scanf("%lld", &i);
    if(n && v[0] != 0){
        puts("-1");
        return 0;
    }
    if(!n){
        if(v[0] != 1) {
            puts("-1");
            return 0;
        }else {
            puts("1");
            return 0;
        }
    }
    vector<ll> S(v);
    for (int i = n-1; i >= 0; --i) {
        S[i] += S[i+1];
    }
    vector<ll> ans(n+1, 1);
    for (int i = 1; i <= n; ++i) {
        if((ans[i-1]-v[i-1])*2 < v[i]){
            puts("-1");
            return 0;
        }
        ans[i] = min(S[i], (ans[i-1]-v[i-1])*2);
    }
    cout << accumulate(ans.begin(),ans.end(), 0LL) << "\n";
    return 0;
}

Measured memory_bytes: 5704
arr = input().split()
arr = list(map(int,arr))
c1 = 0
c2 = 0
for i in range(len(arr)):
    if arr[i] == 5:
        c1 += 1
    elif arr[i] == 7:
        c2 += 1

if c1 == 2 and c2 == 1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
int main()
{
    long long int A,B,K;
    cin >> A >> B >> K;
    if(A>=K){
        cout << A-K << " " << B << endl;
    }
    else if(A<K&&A+B>=K){
        cout << "0 " << A+B-K << endl;
    }
    else{
        cout << "0 0" << endl;
    }
    return 0;
}

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

int abs (int z)
{
	return z > 0 ? z : -z;
}
int min (int a, int b)
{
	return a < b ? a : b;
}
int result(int a[], int n, int k)
{
	int dp[n];
	dp[0]=0;
	for (int i = 1; i < n; ++i)
	{
		dp[i] = dp[i-1]+abs(a[i]-a[i-1]);
		for (int j = 2; j <= min(i,k); ++j)
			dp[i] = min(dp[i], dp[i-j] + abs(a[i]-a[i-j]));
	}
	return dp[n-1];
}

int main()
{
	int n,k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int res = result(a,n,k);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l,m=INT_MAX,ans;
    cin>>n>>l;
    int sum=(n*(l+1-1+n+l-1))/2;
   // cout<<sum<<endl;
    for(int i=1;i<=n;i++)
    {   int k=sum-(i+l-1);
          if(m>abs(sum-k))
          { ans=k;
             m=abs(sum-k);
          }
    }
    cout<<ans;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int m;
    while (cin >> m, m) {
        int mx = 1001;
        vector<int> a(m), b(m);
        REP(i, 0, m) {
            cin >> a[i] >> b[i];
        }
        auto dp = make_v(m + 1, mx, 0LL);
        dp[0][0] = 1;
        REP(i, 0, m) {
            REP(j, 0, mx) {
                REP(k, 0, b[i] + 1) {
                    if (j + k * a[i] < mx) {
                        dp[i + 1][j + k * a[i]] += dp[i][j];
                    }
                }
            }
        }

        int g;
        cin >> g;
        REP(i, 0, g) {
            int n;
            cin >> n;
            cout << dp[m][n] << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3280
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

void solve(string s, string t)
{
  int i, j, checker = 0;

  if (s.size() < t.size()) {
    cout<<"UNRESTORABLE"<<endl;
    return;
  }

  for (i = s.size() - t.size(); i >= 0; i--) {
    REP (j, t.size()) {
      if (!(t[j] == s[i + j] || s[i + j] == '?')) break;
      //cout<<s[i + j]<<t[j]<<' ';
      if (j == t.size() - 1) {
        REP (k, j + 1) {
          s[i + k] = t[k];
          //cout<<s[i + k]<<' ';
        }
        checker = 1;
      }
      if (checker) break;
    }
    if (checker) break;
    //cout<<s<<endl;
  }

  REP (i, s.size()) if (s[i] == '?') s[i] = 'a';

  if (checker) cout<<s<<endl;
  else cout<<"UNRESTORABLE"<<endl;
}

int main()
{
  string Sp,T;

  cin>>Sp>>T;

  //cout<<Sp.size()<<T.size()<<endl;

  solve(Sp, T);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M = 1e9+7 ;
long long sum=0;
long long n,k;
long long a[2005];
long long b[2005];
int main()
{
	cin >> n >> k;
	for(int i=0;i<n;i++) {
		cin >>a[i]; 
	}
	for(int i=0;i<n;i++) {
		for(int j=i+1;j<n;j++) {
			if(a[i]>a[j]) {
				sum++;
			}
		}
	}
	sum=(sum*k)%M;
	memset(b,0,sizeof(b)) ;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(a[i]>a[j]) b[i]++;
		}
	}
	k=k*(k-1)/2%M;
	for(int i=0;i<n;i++) {
		sum=(sum%M+(b[i]*k%M))%M;	
	}
	cout << sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

const long long int INF=1e15;

int main() {
    long long int N;
    cin >> N;
    
    long long int imax=sqrt(N)+1;
    long long int dis_min=INF;
    for(long long int i=1; i<imax; i++) {
        if(N%i==0) {
            dis_min = min(dis_min, i+N/i-2);
        }
    }

    cout << dis_min << endl;

    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int tmp, CaseNum = 1;
 
    while ((tmp = scan.nextInt()) != 0) {
      System.out.printf("Case %d: %d\n", CaseNum++, tmp);
    }
  }
}


Measured memory_bytes: 66832
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[100];
  for(int i=0; i<n; i++) cin >> a[i];

  for(int i=0; i<n-1-i; i++) swap(a[i], a[n-1-i]);

  for(int i=0; i<n; i++){
	if(i) cout<<" ";
	cout << a[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3104
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>

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

typedef vector<int> vi;
typedef vector<vi> vvi;

int main()
{
	for(;;){
		map<int, int> deg;
		for(;;){
			int a, b;
			if(scanf("%d%d", &a, &b) == EOF)
				return 0;
			if(a == 0)
				break;
			deg[a]++;
			deg[b]++;
		}

		bool ok = true;
		for(map<int, int>::iterator itr=deg.begin(); itr!=deg.end(); ++itr){
			if(itr->first == 1 || itr->first == 2)
				ok &= itr->second % 2 == 1;
			else
				ok &= itr->second % 2 == 0;
		}
		puts(ok ? "OK" : "NG");
	}
}

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

int gcd(int p,int q){
    if(p%q == 0){
        return q;
    }
        return gcd(q,p%q);
}

int main(){
    int n; cin >> n;
    vector<int> A(n,0);
    for(int i=1;i<n;i++){
        cin >> A[i];
    }
    vector<int> boss(n,0);
    rep(i,n){
        if(A[i]!=0){
            boss[A[i]-1]++;
        }
    }

    rep(i,n){
        cout << boss[i] << endl;
    }
}



Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll m=ll(sqrt(n));
    ll x,y;
    for(ll i=m;i>=1;i--){
        if(n%i==0){
            x=i;
            y=n/i;
            break;
        }

    }
    cout << x+y-2<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,n,t,a,b,c,l,r;
    cin>>n;
    vector<ll>v(n);
    for(i=0; i<n; i++)
        cin>>v[i];
    sort(v.rbegin(),v.rend());
    ll ans=0;
    ans+=v[0];
    i=1;
    x=0;
    n-=2;
    while(n--)
    {
        ans+=v[i];
        x++;
        if(x==2)
        {
            i++;
            x=0;
        }
    }
    cout<<ans<<'\n';
}






Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

struct Edge{int to,weight; Edge(int t, int w) : to(t), weight(w) {}};
using DirectedGraph = vector<vector<Edge>>;
using UndirectedGraph = vector<vector<int>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<P> itv(n);
    REP(i,n){
        cin>>itv[i].second>>itv[i].first;
    }
    VSORT(itv);
    int t = 0;
    REP(i,n){
        //cout<<itv[i].second<<":"<<itv[i].first<<endl;
        if(t+itv[i].second<=itv[i].first){
            t += itv[i].second;
        }
        else{
            cout<<"No"<<endl;
            return 0;
        }
        //cout<<t<<endl;
        //cout<<t<<endl;
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		String wk = "";

		try {
			scanner = new Scanner(System.in);
			wk = scanner.next();

			System.out.println(wk.replaceAll(",", " "));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numK = 0;
		int s = 0;

		try {
			scanner = new Scanner(System.in);
			numK = scanner.nextInt();
			s = scanner.nextInt();

			int startK = 0;
			if (numK <= s / 3) {
				startK = numK;
			}
			int res = 0;
			for (int i = 0; i <= numK; i++) {
				for (int j = 0; j <= numK; j++) {
					if (s - i - j < 0) {
						break;
					} else if (s - i - j <= numK) {
						res++;
					}
				}
			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int lineSX = 0;
		int lineSY = 0;
		int lineTX = 0;
		int lineTY = 0;

		try {
			scanner = new Scanner(System.in);
			lineSX = scanner.nextInt();
			lineSY = scanner.nextInt();
			lineTX = scanner.nextInt();
			lineTY = scanner.nextInt();

			StringBuilder builderRes = new StringBuilder();

			StringBuilder builderGo = new StringBuilder();
			StringBuilder builderBack = new StringBuilder();

			for (int i = 0; i < lineTY - lineSY; i++) {
				builderGo.append("U");
				builderBack.append("D");
			}
			for (int i = 0; i < (lineTX - lineSX); i++) {
				builderGo.append("R");
				builderBack.append("L");
			}

			builderRes.append(builderGo).append(builderBack);
			builderGo.setLength(0);
			builderBack.setLength(0);

			builderGo.append("L");
			builderBack.append("R");

			for (int i = 0; i < (lineTY - lineSY) + 1; i++) {
				builderGo.append("U");
				builderBack.append("D");
			}
			for (int i = 0; i < (lineTX - lineSX) + 1; i++) {
				builderGo.append("R");
				builderBack.append("L");
			}

			builderGo.append("D");
			builderBack.append("U");

			builderRes.append(builderGo).append(builderBack);

			System.out.println(builderRes.toString());

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 25300
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;cin>>s;
string t="";
for(int i=0;i<s.size();i++){
if(s.at(i)=='B'){
if(t.size()){
t.pop_back();
}
}
else{
t+=s.at(i);
}
}
cout<<t<<endl;
}

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

"""
参考：http://blog.livedoor.jp/misteer/archives/9017497.html
　　　https://www.hamayanhamayan.com/entry/2018/04/21/225805
・累積和
・累積max
"""

N, C = map(int, input().split())
x, v = [0], [0]
for i in range(N):
    _x, _v = map(int, input().split())
    x.append(_x)
    v.append(_v)
# 累積和
sm_r = [0] * (N+1)
for i in range(1, N+1):
    sm_r[i] = sm_r[i-1] + v[i] - (x[i] - x[i-1])
sm_l = [0] * (N+1)
sm_l[N] = v[N] - (C - x[N])
for i in range(N-1, 0, -1):
    sm_l[i] = sm_l[i+1] + v[i] - (x[i+1] - x[i])
# 累積max
mx_r = [0] * (N+2)
cal = 0
for i in range(1, N+1):
    cal += v[i] - (x[i] - x[i-1])
    mx_r[i] = max(cal, mx_r[i-1])
mx_l = [0] * (N+2)
mx_l[N] = cal = v[N] - (C - x[N])
for i in range(N-1, 0, -1):
    cal += v[i] - (x[i+1] - x[i])
    mx_l[i] = max(cal, mx_l[i+1])

ans = 0
for i in range(N+1):
    # 右回り→左回り(max(右回りのみ, 逆走もする, 今までの最大))
    ans = max(sm_r[i], sm_r[i] - x[i] + mx_l[i+1], ans)
    # 左回り→右回り
    if i != 0:
        ans = max(sm_l[i], sm_l[i] - (C - x[i]) + mx_r[i-1], ans)
print(ans)


Measured memory_bytes: 28432
// Written by newbiechd
#include <cstring>
#include <iostream>
#include <string>

const int maxN = 13;
int n;

const std::string ans[][7] = {
  {
    "aabc",
    "ddbc",
    "efgg",
    "efhh"
  },
  {
    "aabbd",
    "ccf.d",
    "eefgg",
    "..hij",
    "..hij"
  },
  {
    "aabbcc",
    "ddeeff",
    "ghi...",
    "ghi...",
    "...jkl",
    "...jkl"
  },
  {
    "aabbcc.",
    "ddee..h",
    "ffgg..h",
    "....ijk",
    "....ijk",
    "....lmn",
    "....lmn"
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  
  if (n < 3) {
    printf("-1\n");
    return 0;
  }
  if (n == 3) {
    std::cout << "aa.\n..a\n..a\n";
    return 0;
  }

  int k = (n & 3) + 4;
  for (int i = 0; i < n - k; ++i) {
    std::string str(n, '.');
    str.replace(i / 4 * 4, 4, ans[0][i % 4]);
    std::cout << str << '\n';
  }
  for (int i = n - k; i < n; ++i) {
    std::string str(n, '.');
    str.replace(n - k, k, ans[k - 4][i + k - n]);
    std::cout << str << '\n';
  }
  return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<cstring>
using namespace std;
const int M = 2e5 + 50;
long long value[M] = {0};
long long ans[M] = {0};
long long vis[M] = {0};
map<long long,long long> mp;
long long cl(long long i){
	if(mp[i] == 0 || vis[i] == 1)return value[i];
	value[i]+=cl(mp[i]);
	vis[i] = 1;
	return value[i];
}
int main(){
	long long n,q;
	mp.clear();
	scanf("%lld%lld",&n,&q);
	for(long long i = 0; i < n-1; i++){
		long long a,b;
		scanf("%lld%lld",&a,&b);
		mp[b] = a;
	}
	for(long long i = 0; i < q; i++){
		long long jd,z;
		scanf("%lld%lld",&jd,&z);
		value[jd] += z;
	}
	for(long long i = 1; i <= n; i++){
		if(vis[i] == 0)
			long long fw = cl(i);
		if(i!=1)
			printf(" ");
		printf("%lld",value[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 19072
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,r=0,m=0;
	char c[200];
	scanf("%d\n%s",&N,c);
	for(int i=0;i<N;i++)
	{
		if(c[i]=='D') r--;
		else r++;
		m=max(r,m);
	}
	printf("%d\n",m);
	return 0;
}


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

int gcd(int a,int b)
{
	int r=max(abs(a),abs(b));
	int l=min(abs(a),abs(b));
	if (l==0LL)
	{
		return r;
	}
	return gcd(l,r%l);
}

int main(int argc, char const *argv[])
{
	int n,x;
	cin>>n>>x;
	int a,ans=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a;
		ans=gcd(ans,x-a);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
    const int MAX = 200000;
    int n;
    int a[MAX];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    int maxv = a[1] - a[0];
    int minv = a[0];
    for (int i = 1; i < n; i++) {
        maxv = max(maxv, a[i] - minv);
        minv = min(minv, a[i]);
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 
 
class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int n) {
		Parent = vector<int>(n, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int a) {
		if (Parent[a] < 0) return a;
		return Parent[a] = root(Parent[a]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int a) {
		return -Parent[root(a)];//親をとってきたい]
	}
 
	//AとBをくっ付ける
	bool connect(int a, int b) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		a = root(a);
		b = root(b);
		if (a == b) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(a) < size(b)) swap(a, b);
 
		//Aのサイズを更新する
		Parent[a] += Parent[b];
		//Bの親をAに変更する
		Parent[b] = a;
 
		return true;
	}
};
 

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(m),b(m);
    rep(i,m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }    
    vector<ll> ans(m);
    ans[m-1]=(ll)n*(n-1)/2;

    UnionFind uf(n);
    for(int i=m-1; i>=1; i--){
        if(uf.root(a[i]) != uf.root(b[i])){
            ans[i-1]=ans[i] - (ll)uf.size(a[i])*uf.size(b[i]);
            uf.connect(a[i],b[i]);
        }
        else ans[i-1]=ans[i];
    }
    rep(i,m){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <string>
#include <queue>

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> ship(n+1, vector<int>());
    for (int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        ship[a].push_back(b);
        ship[b].push_back(a);
    }

    bool ans = false;
    queue<P> que;
    que.push(P(1, 0));
    while(!que.empty()) {
        P current = que.front();
        que.pop();
        if (current.first == n) {
            ans = true;
            break;
        }
        if (current.second < 2)
            for (auto i : ship[current.first])
                que.push(P(i, current.second+1));
    }

    cout << (ans?"POSSIBLE":"IMPOSSIBLE") << endl;
}


Measured memory_bytes: 12784
{-# LANGUAGE OverloadedStrings #-}

import Data.Maybe
import qualified Data.ByteString.Char8 as C
import Control.Monad(forM_)

data Tree a = Node (Tree a) a (Tree a)

initTree :: a -> Tree a
initTree x = Node (initTree x) x (initTree x)

insert' :: Int -> a -> Tree a -> Tree a
insert' 0 y (Node l _ r) = Node l y r
insert' i y (Node l x r)
  | mod i 2 == 1 = Node l' x r
  | otherwise = Node l x r'
    where i' = div i 2
          l' = (insert' i' y l)
          r' = (insert' (i' - 1) y r)

at :: Tree a -> Int -> a
at (Node _ x _) 0 = x
at (Node l _ r) i
  | mod i 2 == 1 = at l i'
  | otherwise = at r (i' - 1)
    where i' = div i 2

getInts :: IO [Int]
getInts = do
  ss <- C.getLine
  return $ map (fst . fromJust . C.readInt) $ C.words ss

getIntss :: Int -> IO [[Int]]
getIntss 0 = return []
getIntss n = do
  xs <- getInts
  xss <- getIntss (n - 1)  
  return $ xs : xss

getRoot :: Tree (Int,Int) -> Int -> (Int,Int)
getRoot tree i = if i' == (-1) || i' == i then (i,rank) else getRoot tree i'
  where x@(i',rank) = tree `at` i
  
solve :: [[Int]] -> [C.ByteString]
solve xss = solve' xss tree
  where tree = initTree ((-1),1)

solve' :: [[Int]] -> Tree (Int,Int) -> [C.ByteString]
solve' [] _ = []
solve' ([p,a,b]:xss) tree = if p == 0
  then solve' xss $ if xr == yr then insert' xi (xi, xr+1) (insert' yi (xi,yr) tree) else if xr < yr then (insert' xi (yi,xr) tree) else (insert' yi (xi,yr) tree)
  else t : solve' xss tree 
    where (xi, xr) = getRoot tree a
          (yi, yr) = getRoot tree b
          t = (if xi == yi then "1" else "0")
   
main :: IO ()
main = do
  xs <- getInts
  xss <- getIntss $ xs !! 1
  let ys = solve xss
  forM_ ys $ \y -> C.putStrLn y 

Measured memory_bytes: 72436
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>

using ldouble = long double;
using lint = long long;

constexpr ldouble INF = 1e10;
constexpr ldouble EPS = 1e-10;

void solve() {
    int n;
    lint k;
    std::cin >> n >> k;

    std::vector<ldouble> xs(n);
    for (auto& x : xs) std::cin >> x;

    ldouble ok = INF, ng = 0;
    for (int t = 0; t < 100; ++t) {
        ldouble mid = (ok + ng) / 2;

        lint cnt = 0;
        for (auto x : xs) {
            cnt += lint(std::ceil(x / mid) + EPS) - 1;
        }

        if (cnt <= k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    std::cout << lint(std::ceil(ok) + EPS) << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 6268
#include <stdio.h>
int main(void){
  char buf[100];   
  fgets(buf, sizeof(buf), stdin);
    int n;
    sscanf(buf, "%d", &n);
  
    int amari = n%10;
  
  if(amari == 2||amari==4||amari==5||amari==7 ||amari==9){
    printf("hon\n");
  }else if(amari == 0|| amari==1||amari==6||amari==8){
    printf("pon\n");
  }else if (amari == 3){
    printf("bon\n");
  }
}

Measured memory_bytes: 1652
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 109
using namespace std;

int n,m,K,tot=1,fst[N],pnt[N<<1],nxt[N<<1],dad[N],d[N],eg[N];
int cbn[N<<1][N<<1],fa[N],sum[N],sz[N]; bool vis[N],bo[N];
int gcd(int x,int y){ return y?gcd(y,x%y):x; }
int ksm(int x,int y){
	int z=1; for (; y; y>>=1,x=(ll)x*x%mod) if (y&1) z=(ll)z*x%mod;
	return z;
}
void add(int x,int y){
	pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;
}
int getfa(int x){ return x==fa[x]?x:fa[x]=getfa(fa[x]); }
void mrg(int x,int y){
	x=getfa(x); y=getfa(y);
	if (x==y) return;
	sz[y]+=sz[x]; sum[y]+=sum[x]; fa[x]=y;
}
void dfs(int x,int p){
	int i,y; vis[x]=1;
	for (i=fst[x]; i; i=nxt[i]) if (i^p^1){
		y=pnt[i];
		if (!vis[y]){
			dad[y]=x; d[y]=d[x]+1;
			eg[y]=i>>1; bo[i>>1]=1; sz[i>>1]=0;
			dfs(y,i);
		}
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&K);
	int i,j,x,y;
	for (i=0; i<=m+K; i++)
		for (j=cbn[i][0]=1; j<=i; j++)
			cbn[i][j]=(cbn[i-1][j]+cbn[i-1][j-1])%mod;
	for (i=1; i<=m; i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	for (i=1; i<=m; i++){
		fa[i]=i; sz[i]=sum[i]=1;
	}
	for (i=1; i<=n; i++) if (!vis[i]) dfs(i,0);
	for (i=1; i<=m; i++) if (!bo[i]){
		x=pnt[i<<1]; y=pnt[i<<1|1];
		if (d[x]<d[y]) swap(x,y);
		for (; x!=y; x=dad[x]) mrg(eg[x],i);
	}
	int ans=1;
	for (i=1; i<=m; i++) if (getfa(i)==i){
		if (sz[i]>1)
			ans=(ll)ans*cbn[sum[i]+K-1][K-1]%mod;
		else{
			for (j=1,x=0; j<=sum[i]; j++)
				x=(x+ksm(K,gcd(j,sum[i])))%mod;
			ans=(ll)ans*x%mod*ksm(sum[i],mod-2)%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	ll N,K;
	cin>>N>>K;
	if(N == 0LL){cout<<0<<endl; return 0;}
	if(K == 1LL){cout<<0<<endl; return 0;}
	ll t = N%K;
	cout<<min(t,abs(t-K))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef pair<int,int> P;
#pragma GCC optimize("Ofast")

const int MAX_N = 205;

int N;
char G1[MAX_N][MAX_N];
vector<vector<int>> G;

int bfs(int s){
    int ans = -1;
    vector<bool> visited(N, false);
    vector<int> id(N, -10);

    queue<P> Q;
    Q.push({s,1});
    visited[s] = true;
    id[s] = 1;

    while(!Q.empty()){
        auto now = Q.front();
        Q.pop();
        int v = now.first;
        int ID = now.second;
        ans = max(ans, ID);
        //cout << v << endl;
        for(auto nv: G[v]){
            if(id[nv] == ID + 1 || id[nv] == ID - 1 || id[nv] == -10);
            else return -1;
            if(visited[nv]) continue;
            Q.push({nv, ID + 1});
            visited[nv] = true;
            id[nv] = ID + 1;
        }
        //cout << endl;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    G.resize(N);
    rep(i,N){
        rep(j,N){
            cin >> G1[i][j];
            if(G1[i][j] == '1')G[i].push_back(j);
        }
    }
    int ans = -1;
    rep(i,N) ans = max(ans,bfs(i));
    cout << ans << endl;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

string JOI = "JOI", IOI = "IOI";

int main() {
	string str;
	
	while (cin >> str) {
		int len = str.size(), joi = 0, ioi = 0;
		
		for_(i,0,len-2) {
			if (str.substr(i, 3) == JOI) ++joi;
			if (str.substr(i, 3) == IOI) ++ioi;
		}
		
		cout << joi << endl << ioi << endl;
	}
}

Measured memory_bytes: 1216
use std::io;
use std::io::{BufRead, Write};

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let (d, n): (u32, usize) = {
        let mut split = buf.split_whitespace();
        (
            split.next().unwrap().parse().unwrap(),
            split.next().unwrap().parse().unwrap(),
        )
    };
    writeln!(output,"{}", 100usize.pow(d)*(n+n/100)).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "0 5
", "5\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "1 11
", "1100\n",
        );
    }

    #[test]
    fn case3() {
        test(
            "2 85
", "850000\n",
        );
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> v1;
bool even()
{

for(int i=0;i<v1.size();i++)
{
    
    if(v1[i]%2==0) v1[i]/=2;
    
    else return false;
    
    
}
return true;
    
}

int main()
{
    

int n;
cin>>n;
int ans=0;
while(n--)
{

ll x; cin>>x; v1.push_back(x);
    
}


while(even()) ++ans;

cout<<ans;





    
}




    
    


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

int main(){
  int n;
  cin >> n;
  
  map<int,int> mp;
  for(int i = 0;i < n;i++){
    int num;
    cin >> num;
    mp[num] = i+1;
  }
  
  for(int i = 1;i <= n;i++){
    cout << mp[i] << " ";
  }
  cout << endl;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

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

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi w(n);
    rep(i, n) cin >> w[i];
    int ans = 1e9, s1 = 0, s2 = 0;
    rep(i, n) s2 += w[i];
    rep(i, n-1) {
        s1 += w[i];
        s2 -= w[i];
        ans = min(ans, abs(s1-s2));
    }
    cout << ans << endl;
    return 0;
}


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

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

    vector<int> A(N);
    int sum = 0;
    for (int &a : A)
    {
        cin >> a;
        sum += a;
    }

    int ans = 0;
    for (int a : A)
    {
        if (4 * M * a >= sum)
        {
            ans++;
        }
    }
    if (ans >= M)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import sys
from itertools import combinations as combi
input = sys.stdin.readline
H, W, K = map(int, input().split())
S = [list(map(int, list(input())[: -1])) for _ in range(H)]
res = H + W - 2
for t in range(H):
  for c in combi([x for x in range(1, H)], t):
    s = set(c)
    table = [0] * (t + 1)
    rres = t + 0
    for x in range(W):
      i = 0
      y = 0
      while y < H:
        if y in s: i += 1
        table[i] += S[y][x]
        y += 1
        if table[i] > K: break
      else: continue
      rres += 1
      table = [0] * (t + 1)
      i = 0
      y = 0
      while y < H:
        if y in s: i += 1
        table[i] += S[y][x]
        y += 1
        if table[i] > K: break
      else: continue
      rres = H + W - 2
      break

    #print(c, rres, table)
    res = min(res, rres)
print(res)

Measured memory_bytes: 74680
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NP = Sarray();
            var N = NP[0];
            var P = NP[1];
            var Ai = Sarray();
            var eNum = Ai.Count(a => a % 2 == 0);
            var oNum = Ai.Count() - eNum;
            var cmb = new Combination(51);

            //偶数を1つ以上使い、奇数を使わない場合
            var allE = 0L; ;
            for (var i = 1; i <= eNum; ++i)
            {
                allE += (long)cmb.com(eNum, i);
            }
            //偶数
            if (P == 0)
            {
                //奇数を1つ以上使い、偶数を使わない場合
                var allO = 0L;
                for (var i = 2; i <= oNum; i += 2)
                {
                    allO += (long)cmb.com(oNum, i);
                }
                //何も使わない、偶数のみ使う、奇数のみ、偶数と奇数を使うの足し合わせ
                WriteLine(1 + allE + allO + allE * allO);
                return;
            }
            //奇数を1つ以上使い、偶数を使わない場合
            var allOd = 0L;
            for (var i = 1; i <= oNum; i += 2)
            {
                allOd += (long)cmb.com(oNum, i);
            }
            //奇数のみ、偶数と奇数を使う場合の多幸せ
            WriteLine(allOd + allE * allOd);
            //Out.Flush();
        }
        public class Combination
        {
            double[,] dp;
            public Combination(long n)
            {
                dp = new double[n + 1, n + 1];
                for (var i = 0; i < n + 1; ++i)
                {
                    dp[i, 0] = 1;
                    dp[i, i] = 1;
                }
                for (var i = 2; i < n + 1; ++i)
                    for (var j = 1; j < i; ++j)
                        dp[i, j] = dp[i - 1, j - 1] + dp[i - 1, j];
            }
            public double com(int n, int k)
            {
                if (n < k) return 0;
                if (n < 0 | k < 0) return 0;
                return dp[n, k];
            }
        }
    }
}

Measured memory_bytes: 13492
def main():
    N, K, Q = map(int,input().split())
    A = [K-Q for _ in range(N)]
    for _ in range(Q):
        a = int(input())
        A[a-1] += 1

    for a in A:
        if a > 0:
            print("Yes")
        else:
            print("No")
if __name__ == '__main__':
    main()

Measured memory_bytes: 7892
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if ((a > c && c > b) || (a < c && c < b)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}


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

typedef  long long ll;
typedef long double ld;
using namespace std;
const int N=1e5+5;

#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define point complex<double>
ll mod=1e9+7;
ll inf=2e18;
double eps=1e-10;
double pi=acos(-1);
double dot(point a, point b)
{
    return (conj(a)*b).real();
}
double cross(point a, point b)
{
    return (conj(a)*b).imag();
}
ll add(ll x, ll y)
{
    return (x%mod+y%mod)%mod;
}

map<ll ,ll>mp;
int n;
int main()
{
    cin>>n>>mod;
    ll sum=0;
    mp[sum]++;
    for(int i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        sum=add(sum,x);
        mp[sum]++;


    }
    ll ans=0;
    for(auto i:mp)
    {
        ans+=(i.second*(i.second-1))/2;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 7500
x,n=map(int,input().split())
if n ==0:
    print(x)
else:
    p=list(map(int,input().split()))
    tmp=101
    min_num=101
    for i in range(102):
        if i not in p:
            if tmp > abs(x-i):
                min_num=i
                tmp=abs(x-i)
    print(min_num)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)1e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

bool check(unordered_map<char,bool>& d, int n) {
  string num = to_string(n);
  for(auto digit : num) {
    if(d[digit]) {
      return false;
    }
  }
  return true;
}
void solve() {
  int n,k;
  cin>>n>>k;
  unordered_map<char,bool> d;
  char ch;
  REP(i,0,k-1) {
    cin>>ch;
    d[ch] = true;
  }
  REP(i,n,N*10) {
    if(check(d,i)) {
      cout<<i;
      return;
    }
  }
  assert(false);
}
int main() {
    //freopen("./sort/b2.in","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


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

int main() {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < 1250; ++i) {
        if ((int)(i * .08) == a && (int)(i * .1) == b) {
            cout << i;
            return 0;
        }
    }
    cout << -1;
}


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

int main() {
  int n, l;
  cin>>n>>l;
  int sum = 0;
  if (l >= 0) {
    sum = (n-1)*n/2+(n-1)*l;
  }
  else {
    if ((l+n) < 1) {
      sum = (n-1)*(n-2)/2+(n-1)*l;
    }
    else {
      sum = (n-1)*n/2+n*l;
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        l: usize,
        r: usize,
    }
    let mut div = vec![];
    for x in l..=min(r, l + 2019 * 2) {
        div.push(x % 2019);
    }
    let mut result = INF;
    for j in 0..div.len() {
        for i in 0..j {
            result = min(result, div[i] * div[j] % 2019);
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 2164
N = input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sat = 0

for i in range(len(A)):
    sat += B[A[i] - 1]

    if i > 0 and A[i-1] + 1 == A[i]:
        sat += C[A[i-1] - 1]

print(sat)


Measured memory_bytes: 3060
def main():
    h, w = map(int, input().split())
    S = [list(input()) for _ in range(h)]

    for x in range(h):
        for y in range(w):
            cnt = 0
            if S[x][y] == ".":
                if x != 0:
                    if S[x - 1][y] == "#":
                        cnt += 1
                if y != 0:
                    if S[x][y - 1] == "#":
                        cnt += 1
                if x != h - 1:
                    if S[x + 1][y] == "#":
                        cnt += 1
                if y != w - 1:
                    if S[x][y + 1] == "#":
                        cnt += 1
                if x >= 1 and y >= 1:
                    if S[x - 1][y - 1] == "#":
                        cnt += 1
                if x >= 1 and y < w - 1:
                    if S[x - 1][y + 1] == "#":
                        cnt += 1
                if x < h - 1 and y >= 1:
                    if S[x + 1][y - 1] == "#":
                        cnt += 1
                if x < h - 1 and y < w - 1:
                    if S[x + 1][y + 1] == "#":
                        cnt += 1
                S[x][y] = cnt 
            print(S[x][y], end = "")
        print()



if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	int x = 0, sum = 0;
	for (int i = 0; i < N; i++) {
		int n;
		cin >> n;
		x = max(x, n);
		sum += n;
	}
	sum -= x;

	if (x < sum) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3572
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void trace(int64_t A[], int64_t N) {
	for (int64_t i = 0; i < N; i++) {
		if (i > 0) std::cout << " ";
		std::cout << A[i];
	}
	std::cout << std::endl;
}

int64_t selectionSort(int64_t A[], int64_t N) {
	int64_t sw = 0;
	for(int64_t i = 0; i < N - 1; i++) {
		int64_t min_j = i;
		for (int64_t j = i; j < N; j++) {
			if(A[j] < A[min_j]) min_j = j;
		}
		std::swap(A[i], A[min_j]);
		if (i != min_j) sw++;
	}
	return sw;
}

void solve()
{
	int64_t A[100], N, sw;

	std::cin >> N;
	for (int64_t i = 0; i < N; i++) {
		std::cin >> A[i];
	}

	sw = selectionSort(A, N);

	trace(A, N);
	std::cout << sw << std::endl;

	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}



Measured memory_bytes: 3204
a = list(map(int,input().split()))
A = a[0]
B = a[1]
C = a[2]
aa = input()
K = int(aa)

flag = 0
r = 0

while r <= K:
    if A < B:
        if B < C:
            flag = 1
            break
        else:
            C = C*2
            r = r + 1
    else:
        B = B*2
        r = r + 1
if flag == 0:
    print('No')
else:
    print('Yes')


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


int main(){
  string s;
  cin >> s;
  bool a,b;
  a=false;
  b=false;
  for(int i=0;i<3;++i){
    if(s[i]=='A'){
      a=true;
    }else{
      b=true;
    }
  }
  if(a==true && b==true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256