akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

class DisjointSet{
public:
  vector<int>rank,p;
  
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++)makeset(i);
  }

  void makeset(int x){
    p[x]=x;
    rank[x]=0;
  }

  bool same(int x,int y){
    return(findset(x)==findset(y));
  }
  
  void unite(int x,int y){
    link(findset(x),findset(y));
  }

  void link(int x,int y){
    if(rank[x]>rank[y])p[y]=x;
    else{
      p[x]=y;
      if(rank[x]==rank[y]){
	rank[y]++;
      }
    }
  }

  int findset(int x){
    if(x!=p[x]){
      p[x]=findset(p[x]);
    }
    return(p[x]);
  }
};

int main(){
  int n,a,b,q;
  int t;
  
  cin>>n>>q;
  DisjointSet ds=DisjointSet(n);

  for(int i=0;i<q;i++){
    cin>>t>>a>>b;
    if(t==0)ds.unite(a,b);
    else if(t==1){
      if(ds.same(a,b))cout<<1<<endl;
      else cout<<0<<endl;
    }
  }

  return(0);
}

Measured memory_bytes: 1276
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e5 + 7;
int lst[Max];

int main()
{
	string str;
	cin >> str;
	cout << str[0] << str.size() - 2 << str[str.size() - 1];
}

Measured memory_bytes: 3140
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var _S = cin.Read;
            var S = _S.ToCharArray();
            var flag = true;
            for(int i = 0; i < S.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (S[i] == 'L') flag = false;
                }
                else
                {
                    if (S[i] == 'R') flag = false;
                }
            }
            if (flag)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }

        /*public long C(long n, long r)
        {
            if (r == 0 || r == n) return 1L;
            if (n < r) return 0L;
            long[,] Pascal = new long[n + 1, n + 1];
            Pascal[0, 0] = 1;
            for (long i = 1; i <= n; i++)
            {
                Pascal[i, 0] = 1;
                Pascal[i, i] = 1;
                for (long j = 1; j < n; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[n, r];
        }*/

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

int main() {
	// your code goes here
	long long int n;cin>>n;
	if(n%2){
		cout<<"0";return 0;
	}
	n/=2;long long int sum=0;
	long long int q=5;
	long long int temp=n/q;
	while(temp>0){
		sum+=temp;
		q*=5;
		temp=n/q;
	}
	cout<<sum<<endl;
	
	return 0;
}


Measured memory_bytes: 256
s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=list(map(int,input().split()))
v=[list(map(int,input().split())) for i in range(s[2])]
a=10**6
d=0
e=0
for i in range(s[2]):
  d=v[i][0]-1
  e=v[i][1]-1
  b=t[d]+u[e]-v[i][2]
  a=min(a,b)
f=min(t)
e=min(u)+f
a=min(a,e)
print(a)

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(auto &e : A) cin >> e;
    sort(A.begin(), A.end());
    int ans = accumulate(A.begin(), A.end(), 0);
    if(ans % 10) {
        cout << ans << '\n';
    } else {
        for(auto &e : A) {
            if(e % 10) {
                cout << ans - e << '\n';
                return 0;
            }
        }
        cout << 0 << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(void){
	int s;

	std::scanf("%d",&s);

	std::printf("%lld:",s/3600);
	s = s%3600;
	std::printf("%lld:",s/60);
	s = s%60;
	std::printf("%lld\n",s);

	return 0;
}

Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long int sum=0;
    for (int i=1;i<=n;i++) {
        if ( (i%3==0&&i%5==0)||(i%3==0)||(i%5==0) ) {
            continue;
        } else {
            sum+=i;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
using ll = long long;
const ll INF = 1e9;

int main() {
    int N;
    cin >> N;
    ll A[N], ans = 0;
    for (int i = 0; i < N; i++) cin >> A[i];

    for (int i = 0; i < N; i++) {
        if (A[i] == 0) continue;
        if (i > 0 && A[i - 1] == 1) {
            ans++;
            A[i - 1] = 0;
            A[i]--;
        }
        if (A[i] % 2 == 0) {
            ans += A[i] / 2;
            A[i] = 0;
        } else {
            ans += A[i] / 2;
            A[i] = 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
f = lambda: map(int,input().split())
n,m,q = f()
d = [[0 for _ in range(n)]for _ in range(n)]
for _ in range(m):
    l,r = f()
    d[l-1][r-1] += 1
P,Q = [],[]
for _ in range(q):
    a, b = f()
    P.append(a)
    Q.append(b)

for i in range(n):
    for j in range(1,n):
        d[i][j] += d[i][j-1]
for i in range(n-2,-1,-1):
    for j in range(n):
        d[i][j] += d[i+1][j]
for i in range(q):
    print(d[P[i]-1][Q[i]-1])

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

int main() {
  int n;
  cin>>n;
  for(int i=0;i<=n;i++){
    if(i*108/100==n){
      cout<<i<<endl;
      break;
    }
    else if(i==n) cout<<":("<<endl;
  }
}


Measured memory_bytes: 256
let inputs = require('fs').readFileSync('/dev/stdin', 'UTF-8').split('\n');
for( let i=0; i<inputs.length; i++ ) {
  const h = inputs[i].split(' ').map(Number)[0];
  const w = inputs[i].split(' ').map(Number)[1];
  let rect = '';
  let width = '';
  let height = '';
  if ( h === 0 && w === 0 ) {
    break;
  } else {
    for (let i=1; i<=w; i++) {
      width += '#';
    }

    if (h <= 1) {
      rect = width + '\n';
    } else {
      for (let i=1; i<=h; i++) {
        rect += width + '\n';
      }
    }
    console.log(rect);
  }
}



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

#include<stdlib.h>
#include<iostream>
#include<math.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define Min(a,b) (a<b?a:b)
#define Max(a,b) (a>b?a:b)
#define PI 3.1415926535897932
using namespace std;

int main()
{
IOS;
int n;
cin>>n;
int a=0,w=0,t=0,r=0;
while(n--){
	string s;
	cin>>s;
	if(s=="AC")
		a++;
	else if(s=="WA")
		w++;
	else if(s=="TLE")
		t++;
	else if(s=="RE")
		r++;

}
cout<<"AC x "<<a<<endl;
cout<<"WA x "<<w<<endl;
cout<<"TLE x "<<t<<endl;
cout<<"RE x "<<r<<endl;




return 0;
}

Measured memory_bytes: 3656
n=int(input())
X=0
Y=0
T=0
for i in range(n):
    t,x,y=map(int,input().split())
    if t-T>=abs(X-x)+abs(Y-y) and (t-T)%2==(abs(X-x)+abs(Y-y))%2:
        T=t
        X=x
        Y=y
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 9128
N, D = map(int, input().split())
arr = []
for i in range(N):
    arr.append(list(map(int, input().split())))

ans = 0
for i in range(N):
    for j in range(N):
        if i < j:
            dis = 0
            for k in range(D):
                dis += (arr[i][k]-arr[j][k])**2
            dis = pow(dis, 1/2)
            if abs(int(dis) - dis) < 0.1**10:
                ans += 1

print(ans)

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N),B(N);
    for (int i=0;i<N;++i) cin >> A[i] >> B[i];
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    int ans=B[N/2]-A[N/2]+1+(N&1?0:B[N/2-1]-A[N/2-1]);
    cout << ans << '\n';
}

Measured memory_bytes: 4780
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

const P: usize = 1000000007;

fn main() {
    let n = get!(usize);
    let mut r: usize = 1;
    for i in 1..n+1 {
        r = (r * i) % P;
    }
    println!("{}", r);
}

Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax=1e5;
int N;
ll L, A[Nmax];

int main(){
	cin >> N >> L;
	for(int i=0; i<N; i++) cin >> A[i];

	int n = -1;
	for(int i=0; i<N-1; i++){
		if(A[i]+A[i+1]>=L){
			n = i;
			break;
		}
	}

	if(n < 0){
		cout << "Impossible" << endl;
		return 0;
	}

	cout << "Possible" << endl;
	for(int i=0; i<n; i++){
		cout << i+1 << endl;
	}
	for(int i=N-2; i>=n; i--){
		cout << i+1 << endl;
	}

	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int q;
    cin >> s >> q;
    vector <int> t(q,0);
    vector <int> f(q,0);
    vector <char> c(q,'\0');
    for(int i = 0; i<q; i++){
        cin>> t[i];
        if(t[i]==2){
            cin >> f[i] >> c[i];
        }
    }
    bool isInversed = false;
    string ans = s;
    string addHead = "";
    for(int i = 0; i<q; i++){
        if(t[i]==1){
            if(isInversed){
                isInversed = false;
            }else{
                isInversed = true;
            }
        }else{
            if(f[i]==1){
                //head
                if(isInversed){
                    ans = ans + c[i];
                }else{
                    addHead+=c[i];
                    //ans = c[i] + ans;
                }
            }else{
                //tail
                if(isInversed){
                    addHead+=c[i];
                    //ans = c[i] + ans;
                }else{
                    ans = ans + c[i];
                }
            }
        }
    }
    string finalAns ="";
    if(isInversed){
        for(int i = 0; i<ans.length(); i++){
            finalAns += ans[ans.length()-1-i];
        }
        finalAns+=addHead;
    }else{
        for(int i = 0; i<addHead.length(); i++){
            finalAns += addHead[addHead.length()-1-i];
        }
        finalAns+=ans;
    }
    cout << finalAns << endl;
    // for(int i = 0; i<ans.length(); i++){
    //     if(isInversed){
    //         cout << ans[ans.length()-1-i];
    //     }else{
    //         cout << ans[i];
    //     }
    // }
    // cout << endl;
    #if 0
    cout << endl;
    for(int i = 0; i<q; i++){
        cout << t[i] << " " << f[i] << " " << c[i] << endl;
    }
    cout << endl;
    #endif


    return 0;
}

Measured memory_bytes: 3680
using namespace std;
#include <bits/stdc++.h>
#define FASTIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define ll long long
#define debug(x) cout << #x << " = " << x << endl
vector<int> is_prime(1000001,0);
bool visited[1000001] = {false};
void seive(int n)
{
	for (int i = 2; i <n; i++)
	{
		if (is_prime[i] == 0)
		{
			for (int j = i; j <n; j += i)
			{
				is_prime[j] = i;
			}
		}
	}
}
bool ch1(int arr[], int n)
{
	for (int l = 0; l < n; l++)
	{
		int x = arr[l];
		while (x > 1)
		{
			int ch = is_prime[x];
			if (visited[ch])
				return false;
			visited[ch] = true;
			while (x % ch == 0 && x > 1)
			{
				// for checking its lower multiples which divides it
				x /= ch;
			}
		}
	}
	return true;
}
bool ch2(int arr[], int n)
{
	int g = arr[0];
	for (int i = 1; i < n; i++)
	{
		g = __gcd(arr[i], g);
	}
	if (g == 1)
		return true;
	else
		return false;
}
void solve()
{
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	if (ch1(arr, n))
	{
		cout << "pairwise coprime" << endl;
		return;
	}
	else if (ch2(arr, n))
	{
		cout << "setwise coprime" << endl;
	}
	else
		cout << "not coprime" << endl;
}
int main()
{
	FASTIO
	long long int t;
	t = 1;
	seive(1000001);
	while (t--)
		solve();
	return 0;
}


Measured memory_bytes: 11100
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    a = list(map(int, readline().split()))
    a = sorted(a)[::-1]

    A, B = 0, 0
    sa, sb = 0, 1
    for i in range(N):
        sa += (-1)**i
        sb += (-1)**(i+1)
        A += sa * a[i]
        B += sb * a[i]

    print(A-B)


main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
using namespace std;

int k, x;

int main()
{
  cin >> k >> x;
  if (500 * k >= x)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

typedef long long ll;

int main () {

    ll K,S;
    cin >> K >> S;
    ll ans = 0;
    for(int x=0; x<=K; x++) {
	for(int y=0; y<=K; y++) {
	    if ( 0 <= S-x-y and S-x-y <= K) {
		ans++;
	    }
	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int a,b;
    char c;
    cin >> a >> c >> b;
    if(c=='+'){
        cout << a+b << endl;
    }else{
        cout << a-b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long i,n,a[100010],b[100010],ans,tmp1,tmp2;
int main(){
  cin>>n;
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  if(n&1){
    for(i=0;i<n/2;i++)b[i*2+1]=a[i];
    b[n-1]=a[n/2];
    for(i=0;i<n/2;i++)b[i*2]=a[n/2+1+i];
    for(i=0;i<n-1;i++)tmp1+=abs(b[i+1]-b[i]);

    b[0]=a[n/2];
    for(i=0;i<n/2;i++)b[i*2+2]=a[i];
    for(i=0;i<n/2;i++)b[i*2+1]=a[n/2+1+i];
    for(i=0;i<n-1;i++)tmp2+=abs(b[i+1]-b[i]);
    
    ans=max(tmp1,tmp2);
  }else{
    for(i=0;i<n/2;i++)b[i*2+1]=a[i];
    for(i=0;i<n/2;i++)b[i*2]=a[n/2+i];
    for(i=0;i<n-1;i++)ans+=abs(b[i+1]-b[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define ins				insert
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull				unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>
#define usi 			unordered_set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}

void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
bool cmp(Node A,Node B)
{
	return A.a<B.a;
}
const int Max=1e5+1;

int32_t main()
{
	c_p_p();
	int n;
	cin>>n;
	if(n%1000)
	{
		cout<<1000-n%1000;
	}
	else cout<<0;
	return 0;
}
	

Measured memory_bytes: 3608
program ccc
implicit none

integer :: n, m, i, lmax, rmin, res
integer,allocatable,dimension(:) :: l, r

read*, n, m
allocate(l(m),r(m))
do i=1,m
read*, l(i), r(i)
end do

lmax=maxval(l)
rmin=minval(r)

res=rmin-lmax+1

if(res<0) then
write(*,'(i0)') 0
return
end if
write(*,'(i0)') res

end program

Measured memory_bytes: 1024
program prob5
    implicit none
    integer :: K, T
    integer, allocatable, dimension(:) :: a
    integer :: m
    read(*,*) K, T  
    allocate(a(T))
    read(*,*) a
    m = maxval(a)
    if(mod(K, 2) == 0) then
        write(*,*) max(0,(m - K/2)*2-1)
    else
        write(*,*) max(0,(m - K/2)*2-2)
    end if

    deallocate(a)

    stop
contains
end program prob5

Measured memory_bytes: 2832
var
	S:String;
	ans,now,i,n:Longint;
begin
	readln(S);
	n:=length(S);
	for i:=1 to n do if i mod 2<>ord(S[i])-48 then inc(now);
	ans:=now;
	now:=0;
	for i:=1 to n do if(i+1)mod 2<>ord(S[i])-48 then inc(now);
	if ans>now then ans:=now;
	writeln(ans);
end.


Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 int main() {
 int n;
 string s;
 cin >> n >> s;
 int ans = 0;
 for(int i = 0; i <= n - 3; i++) {
 if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

const llong MOD = (1e9) + 7;
llong n;
llong a[10005];
llong d[1000005];

llong mod_pow(llong a, llong x) {
    llong r = 1;

    while (x) {
        if (x & 1) {
            r *= a;
            r %= MOD;
        }
        a *= a;
        a %= MOD;
        
        x >>= 1;
    }

    return r;
}

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

    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        llong tmp = a[i];
        
        llong j = 2;
        while (j * j <= tmp) {
            llong cnt = 0;
            while (tmp % j == 0) {
                tmp /= j;
                cnt++;
            }

            d[j] = max(d[j], cnt);
            j++;
        }
        if (tmp > 1) {
            d[tmp] = max(d[tmp], 1ll);
        }
    }

    llong l = 1;
    for (int i = 2; i <= 1000000; i++) {
        l *= mod_pow(i, d[i]);
        l %= MOD;
    }

    llong ans = 0;
    for (int i = 0; i < n; i++) {
        ans += l * mod_pow(a[i], MOD - 2) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6656
import java.util.Scanner;
class Main{
    public static void main(String[]arge){
        Scanner sc=new Scanner(System.in);
        
        int n=sc.nextInt(); 
        int[] R = new int[n];
                
        for(int i=0; i<n; i++){
            R[i]=sc.nextInt();
            } 
        int answer=R[1]-R[0];
        int min=R[0];
        for(int i=1; i<n; i++){
            
            if(answer<R[i] - min)
                answer=R[i]-min;
            if(R[i]<min){
                    min=R[i];
                }
            
            
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 97556
package main

import (
	"fmt"
	"regexp"
)


func main() {
	var s string
	fmt.Scanf("%s", &s)
	san := `^RRR$`
	ni := `^SRR$`
	ni2 := `^RRS$`
	ichi := `^RSR$`
	ichi2 := `^SSR$`
	ichi3 := `^RSS$`
	ichi4 := `^SRS$`

	if regexp.MustCompile(san).Match([]byte(s)) {
		fmt.Println(3)
		return
	} else if regexp.MustCompile(ni).Match([]byte(s)) ||
		regexp.MustCompile(ni2).Match([]byte(s)) {
		fmt.Println(2)
		return
	} else if regexp.MustCompile(ichi).Match([]byte(s)) ||
		regexp.MustCompile(ichi2).Match([]byte(s)) ||
		regexp.MustCompile(ichi4).Match([]byte(s)) ||
		regexp.MustCompile(ichi3).Match([]byte(s)) {
		fmt.Println(1)
		return
	}
	fmt.Println(0)
}


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

int old_t = 0, old_x = 0, old_y = 0;
int new_t, new_x, new_y;

int dirx[4] = { 1, 0, -1, 0 };
int diry[4] = { 0, 1, 0, -1 };
bool walk( int t, int x, int y )
{
	int diff_t = t - old_t;
	int diff_x = x - old_x;
	int diff_y = y - old_y;
	if( diff_x + diff_y > diff_t ) {
		return false;
	}
	if( ( (diff_x + diff_y) % 2 ) != 0 && (diff_t % 2) != 0 ) {
		return true;
	}
	if( ( (diff_x + diff_y) % 2 ) == 0 && (diff_t % 2) == 0 ) {
		return true;
	}
	return false;
}

int main()
{
	int ans = 0;
	int n;
	int t, x, y;

	cin >> n;
	for( int i = 0; i < n; i++ ) {
		cin >> t >> x >> y;
		new_t = t;
		new_x = x;
		new_y = y;
		bool b = walk( t, x, y );
		if( b == false ) {
			ans = 1;
		}
	}
	if( ans == 0 ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>
#include <complex>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

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

int a[100007];
int n,ans;

struct pp
{
	int num,tot;
};

pp b1[100009],b2[100009];

bool cmp(pp a,pp b)
{
	return a.tot>b.tot;
}


int main()
{
	FAST;
	cin >> n;
	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=1;i<=n-1;i+=2) b1[a[i]].tot++;
	for(int i=2;i<=n;i+=2) b2[a[i]].tot++;
	for(int i=1;i<=100003;i++) b1[i].num=b2[i].num=i;

	sort(b1+1,b1+100003,cmp);
	sort(b2+1,b2+100003,cmp);

	if(b1[1].num!=b2[1].num) ans=n-b1[1].tot-b2[1].tot;
	else ans=min(n-b1[1].tot-b2[2].tot,n-b2[1].tot-b1[2].tot);

	//cout<<b1[1].tot<<' '<<b1[2].tot<<' '<<b1[1].num<<' '<<b1[2].num;
	//cout<<max11<<' '<<max12<<' '<<max21<<' '<<max22;

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 2176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        a: u16,
        b: u16,
    }
    if a >= 13 {
        println!("{}", b);
    } else if a < 13 && a >= 6 {
        println!("{}", b / 2);
    } else {
        println!("{}", 0);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

#define WALL '#'

int main(void)
{
	int H, W;
	cin >> H >> W;

	cout << string(W+2, WALL) << endl;

	for(int i=0; i<H; i++)
	{
		string str;
		cin >> str;

		cout <<  WALL << str << WALL << endl;
	}

	cout << string(W+2, WALL) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <stdlib.h>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  string s;
  int min = 10000;
  int a;
  cin >> s;
  for (size_t i = 2; i < s.length(); i++){
    a = (s[i-2]- 48) * 100 + (s[i-1] - 48) * 10 + s[i] - 48;
    min = abs(753 - a) < min ? abs(753 - a): min;
  }
  cout << min << endl;
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 1000000;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }

int main(){
  ll a, b;
  cin >> a >> b;
  ll c = gcd(a, b);
  cout << a/c*b << endl;
}

Measured memory_bytes: 3628
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
typedef long long LL;
int main(){
	LL d,n,ans,emp;
	cin>>d>>n;
	emp=pow(100,d);
	ans=n*emp;
	if(n==100){
		ans+=emp;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
public class B {
    public static void Main(){
        string line = Console.ReadLine();
        int N = int.Parse(line);
        string[] lines = Console.ReadLine().Split(' ');
        List<long> A = new List<long>();
        // リストの構築
        for (int i=0;i<lines.Length;i++)
        {
            A.Add(long.Parse(lines[i]));
        }
        
        int before = A.Count;
        int after = A.Distinct().Count();
        if (before == after)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 48840
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
ll ncd(ll n,ll d){
    ll x = 1,y=1;
    for(int i=0;i<d;i++){
        x = x*(n-i)%mod;
        y = y*(i+1)%mod;
    }
    return x*modpow(y,mod-2,mod)%mod;
}
int main() {    
    srand(time(NULL));
    for(int j=0;j<14;j++){
    for(int i=0;i<26;i++){
        cout<<i+1<<endl;
    }
    }
    for(int i=0;i<1;i++){

          cout<<rand()%26+1<<endl;  
    }
}
    



Measured memory_bytes: 3664
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)

using namespace std;
const int N=200005;
char s[N];
int n,h[N],cnt,siz[N],mx[N],mx2[N],mn[N];
typedef long long LL;
LL ans;
struct edge{int v,n;} e[N<<1];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

void addedge(int u,int v)
{
	e[cnt]=(edge){v,h[u]},h[u]=cnt++;
	e[cnt]=(edge){u,h[v]},h[v]=cnt++;
}

void pushup(int x,int y)
{
	if(mx[x]<y) mx2[x]=mx[x],mx[x]=y;
	else mx2[x]=max(mx2[x],y);
}

void dfs1(int x,int fa)
{
	if(s[x]=='1') siz[x]=1,mn[x]=0;
	for(int i=h[x]; i!=-1; i=e[i].n)
		if(e[i].v!=fa)
		{
			dfs1(e[i].v,x);
			siz[x]+=siz[e[i].v];
			if(siz[e[i].v]) mn[x]=min(mn[x],mx[e[i].v]+1);
			pushup(x,mx[e[i].v]+1);
		}
}

void dfs2(int x,int fa)
{
	if(fa)
	{
		int tmp;
		if(mx[fa]==mx[x]+1) tmp=mx2[fa]+1; else tmp=mx[fa]+1;
		if(siz[1]-siz[x]>0) mn[x]=min(mn[x],tmp);
		pushup(x,tmp);
	}
	for(int i=h[x]; i!=-1; i=e[i].n)
		if(e[i].v!=fa)
			dfs2(e[i].v,x);
	ans+=max(0,min(mx[x]-1,mx2[x]+1)-mn[x]+1);
}		

int main()
{
	n=getint();
	memset(h,-1,sizeof(h));
	rep(i,1,n-1) addedge(getint(),getint());
	rep(i,1,n) mn[i]=n;
	scanf("%s",s+1);
	dfs1(1,0),dfs2(1,0);
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 14464
#include<iostream>
//#include<cmath>
#include<string>
#include<regex>
using namespace std;

int main(){
  string str,t;
  cin >> str >> t;

  regex q( R"(\?)");
  str = regex_replace(str, q, ".");

  size_t size = t.size();
  int dif = str.size() - size;
  int off;

  for (int i=0; i<dif+1; i++){
    off = dif - i;
    string sub = str.substr(off, size);
//    cout << "sub: " << sub << endl;
    regex re( sub );

    if( regex_match(t,re) ){
        str.replace(off, size, t);
        replace(str.begin(), str.end(), '.', 'a');
        cout << str << endl;
        return 0;
    }
  }

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


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

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr iterator

typedef pair<ll,ll> pii;

const ll MAX=2e5+9;
const ll INF=1e12;

int N,res,cur,arr[MAX],dp[MAX];

signed main()
{
	ios_base::sync_with_stdio(false);

	cin>>N;
	for(int A=1;A<=N;A++)
	{
		cin>>arr[A];
		dp[arr[A]]=max(dp[arr[A]],dp[arr[A]-1]+1);
		res=max(res,dp[arr[A]]);
	}
	cout<<N-res;
	return 0;
}

Measured memory_bytes: 1792
using System ;

 class Program{
   
  static void Main(string[] args){
			int max = 0;

			int N = int.Parse(Console.ReadLine());

			string[] buff = Console.ReadLine().Split(' ');
			int[] V = new int[N];
			int[] C = new int[N];

			for (int i = 0; i < N; i++) V[i] = int.Parse(buff[i]);

			buff = Console.ReadLine().Split(' ');
			for (int i = 0; i < N; i++) C[i] = int.Parse(buff[i]);

			for (int i = 0; i < N; i++)
			{
				if (V[i] - C[i] > 0)
				{
					max += V[i] - C[i];
				}
			}

			Console.WriteLine(max);
  }
}

Measured memory_bytes: 13140
#include <stdio.h>

main(){
  int in,out,temp;

  while(1){
    if(scanf("%d", &in)==EOF) break;
    printf("3C"); 

    temp=in/39;
    out=in-(temp*39);

    if(out==0) printf("39\n");
    else if(out<10) printf("0%d\n", out);
    else printf("%d\n", out);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
if(a+b<c+d)cout<<"Right"<<endl;
if(a+b==c+d)cout<<"Balanced"<<endl;
if(a+b>c+d)cout<<"Left"<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
    cin>>a>>b>>c;
    for(int s=1;s<=1000;s++)
    {
        if((a*s)%b==c)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}

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

int main() {
  int n; cin >> n;
  set<int> mochies;
  
  for (int loop; loop < n; loop++) {
    int d; cin >> d;
    mochies.insert(d);
  }
  
  cout << mochies.size() << endl;
}

Measured memory_bytes: 256
y, x = map(int, input().split())
r = [True] * y
c = [True] * x
z = []
for i in range(y):
    a = input()
    z.append(a)
    for j in range(x):
        if '#' == a[j]:
            c[j] = False
            r[i] = False
for i in range(y):
    if r[i] == False:
        for j in range(x):
            if c[j] == False:
                print(z[i][j], end='')
        print()
        

Measured memory_bytes: 4468
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<time.h>
#include<sstream>
#define MINN -1e8 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF=0x3f3f3f3f3f3f;
const int P=1e9+7;
const int MAXN=32000;
const double pi=3.1415926;
//const int MINN=-1e8;
const ll mod=1000000007;

//map<string,ll> m;
//map<ll,ll> m;

//set<ll> s;

//vector<ll> v;

//scanf("%lld",&t);
int m,d,ans=0;
int main()
{
	cin>>m>>d;
	for(int i=2;i*10<=d;i++)
	{
		for(int j=2;j<10&&i*10+j<=d;j++)
		{
			if(i*j<=m)ans++;
			else break;
		}
	}
	cout<<ans;
	return 0;
}
//ll n,m,t,a,x,ans,res;
//ll powmod(ll a,ll b)     //快速幂 
//{
//	ll tmp=a%mod;
//	ll ans=1;
//	while(b)
//	{
//		if(b&1)ans=ans*tmp%mod;
//		tmp=tmp*tmp%mod;
//		b>>=1;
//	}
//	return ans%mod;
//}


//bool is_prime(ll a)     //判断素数 
//{
//	if(a==2)return 1;
//	else if(a==1||a%2==0)return 0;
//	else
//	{
//		for(ll i=3;i*i<=a;++i)
//		{
//			if(a%i==0)return 0;
//		}
//	}
//	return 1;
//}



Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main extends App {

  for (_ <- 1 to 300) {
    val input = readLine.split(" ").map(_.toInt)
    val (h, w) = (input(0), input(1))

    if (h == 0 && w == 0) sys.exit() else {
      for (e <- 1 to h) {
        if (e == 1 || e == h) println("#" * w) else println("#" + ("." * (w -2)) + "#")
      }
      println()
    }
  }

}



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

/*freopen("testcases/17.in", "r", stdin);
    freopen("output.txt", "w", stdout);*/

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	long long n,a,b,r;
	cin >> n >> a >> b;
	r=n/(a+b)*a;
	r+=min(a,n%(a+b));
	cout << r;
}


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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//ori
#define MOD 1000000007
 
int main() {
  int N, D;
  cin >> N >> D;
  int a = D*2+1;
  int b=N/a, c=N%a;
  if(c>0) b++;
  cout << b << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,ans;
int a[111111],ka[111111];
signed main(){
	
	cin>>n>>m;
	rep(i,n){
		cin>>a[i];
		ka[i]=a[i];
	}
	rep(i,n-2){
		int sum=a[i]+a[i+1];
		if(sum>m){
			a[i+1]-=min(a[i+1],sum-m);
			sum=a[i]+a[i+1];
			if(sum>m){
				a[i]-=sum-m;
			}
		}
	}
	if(a[n-2]+a[n-1]>m){
		a[n-2]-=min(a[n-2],a[n-2]+a[n-1]-m);
		if(a[n-2]+a[n-1]>m){
			a[n-1]-=a[n-2]+a[n-1]-m;
		}
	}
	rep(i,n){
		ans+=ka[i]-a[i];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    map<ll,ll> m;
    m[0]++;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        sum += x;
        m[sum]++;
    }
    ll ans = 0;
    for(auto p : m){
        ans += (p.second)*(p.second-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
s = input()
for i in range(1 << 3):
    ans = ''
    for j in range(3):
        ans += s[j]
        if i>>j & 1:
            ans += '+'
        else: ans += '-'
    ans += s[-1]
    if eval(ans+'==7'):
        print(ans+'=7')
        break

Measured memory_bytes: 38256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007LL;

int main() {
	ll N, K;
	cin >> N >> K;
	ll ans = 0;
	ll x = N / K;
	ans += x*x*x;
	if (K%2==0 && N >= K / 2) {
		ll y = (N - K / 2) / K + 1;
		ans += y*y*y;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/*Be patient && calm!
All our dreams can come true, if we have the courage to pursue them.
The secret of getting ahead is getting started.
It is hard to beat a person who never gives up.
First, solve the problem. Then, write the code.
Fix the cause, not the symptom.
Simplicity is the soul of efficiency.
Make it work, make it right, make it fast.*/
// #include<bits\stdc++.h>
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<algorithm>
#include<sstream>
using namespace std;
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i = j; i < k; i += step)
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop1(i, j, k, step) for (int i = j; i >= k; i -= step)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define rep(i, k) for (int i = (0); i < (k); i++)
#define rrep(i, k) for (int i = k - 1; i >= 0; i--)
#define forall(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lin "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(0)
#define PI 2 * acos(0.0)
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
// bool sortinrev(const pair<int, int> &a,
//                const pair<int, int> &b)
// {
//     return (a.first > b.first);
// }
// bool spOrder(const pair<int, int> &a,
//              const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first > b.first;
//  }





void solve()
{
    string s;
    cin >> s;
    ll sum = 0;
    rep(i,sz(s))
    {
        sum += s[i] - '0';
    }
    if(sum%9)
    {
        cout << "No" << lin;
    } else
    {
        cout << "Yes" << lin;
    }
}





int main()
{
    // auto start = clock();
    fast_io;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    // int c = 1;
    while (t--)
    {
        // cout << "Case " << c << ":"
        // << lin;
        solve();
        // if(t)
        // {
        //     cout << lin;
        // }
        // c++;
    }
    // auto stop = clock();
    // cerr << "time taken:" << double(stop - start) / double(CLOCKS_PER_SEC) << " s" << endl;
    return 0;
}

Measured memory_bytes: 3752
package main
import (
	"bufio"
	"os"
	"fmt"
)

func main(){
	stdin := bufio.NewScanner(os.Stdin)
	var i,o string
	if stdin.Scan(){
		i = stdin.Text()
	}
	switch i {
	case "A":
		o = "T"
	case "T":
		o = "A"
	case "C":
		o = "G"
	case "G":
		o = "C"
	default:
		o = "Unexpected rune"
	}

	fmt.Println(o)
}

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

int main() {
    string N;
    int counter=0;
    int count, counter1;
    cin >>N;
    int a[N.size()];
    for(int i=0;i<N.size();i++){
    a[i]=N.at(i)-'0';}
    int dp[1000010][2]{};
    dp[0][0]=a[0];
    dp[0][1]=11-a[0];
    for(int i=0;i<N.size()-1;i++){
    dp[i+1][0]=min(dp[i][0]+a[i+1],dp[i][1]+a[i+1]);
    dp[i+1][1]=min(dp[i][0]+11-a[i+1],dp[i][1]+9-a[i+1]);}                                  
    cout<<min(dp[N.size()-1][1],dp[N.size()-1][0])<<endl;}


Measured memory_bytes: 13060
#include <stdio.h>
#define for(v, a, n, b) for(int v=a; v<n; v+= b)

int n, d, x;
int a[120];

int main(){
    scanf("%d %d %d", &n, &d, &x);
    for(i, 0,n,1){
        scanf("%d", &a[i]);
    }
    int cant = 0;
    for(i, 0, n, 1){
        for(j, 1, d+1, a[i])
            cant += 1;
    }

    printf("%d\n", cant+x);
}


Measured memory_bytes: 128
from collections import deque
k = int(input())
d = deque()
for i in range(1,10):
    d.append(i)
for i in range(k):
    x = d.popleft()
    m = 10*x+x%10
    if x%10!=0:
        d.append(m-1)
    d.append(m)
    if x%10!=9:
        d.append(m+1)
else:
    print(x)

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

int main() {
    int N;
    cin >> N;
    
    double prob[N + 1];
    double dp[N + 1][N + 1], res = 0;
    
    for(int i = 1; i <= N; ++i)
        cin >> prob[i];
        
    for(int i = 0; i <= N; ++i) {
        for(int j = 0; j <= N; ++j)
            dp[i][j] = 0;
    }    
    
    // first set up the answer for getting 0 heads, for getting 0 heads using 
    // first i coins, it is simply the product of (1 - p1) * (1 - p2) * .. * (1 - pi)
    dp[1][0] = 1.0 - prob[1];
    for(int i = 2; i <= N; ++i)
        dp[i][0] = dp[i - 1][0] * (1.0 - prob[i]);
        
    // next the proability of getting x heads using x coins is simply the product
    // of all pi(s) till here
    dp[1][1] = prob[1];
    for(int i = 2; i <= N; ++i)
        dp[i][i] = dp[i - 1][i - 1] * prob[i];
        
    // now solve for any general dp[i][j], i.e. probability of getting j heads 
    // using the first i coins only. For this, at each index i and some heads j,
    // we can either select a head for the coin at this index or select a tail
    // so, the total result will be -
    // probability of selecting head from this coin * probability of getting j - 1
    // heads from all the previous coins + probability of selecting a tail here
    // * probability of getting j heads from all the previous coins
    
    // note - as getting heads j from first i coins when j > i is impossible, so,
    // we set this probability to 0. Also, since we also computed answers for i == j
    // so, we do not compute it back again
    for(int i = 1; i <= N; ++i) {
        for(int j = 1; j < i; ++j)
            dp[i][j] = dp[i - 1][j] * (1.0 - prob[i]) + dp[i - 1][j - 1] * prob[i];
    }
    
    // now add to res the probability of any heads > N/2 using all the coins
    for(int i = N / 2 + 1; i <= N; ++i)
        res += dp[N][i];
    
    // print answer to the 10th precision
    cout << fixed << setprecision(10) << res;
    
	return 0;
}


Measured memory_bytes: 70528
#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
int main()
{
	int n,i,j,k;
	cin>>n;
	long long a[n+1][n+1];
	for(i=1;i<=n;i++)for(j=1;j<=n;j++)cin>>a[i][j];
	long long ans=0;
	
	for(k=1;k<=n;k++)
	{
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[i][j]>a[i][k]+a[k][j])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			ans+=a[i][j];
			for(k=1;k<=n;k++)
			{
				if(k!=i and k!=j and a[i][k]+a[k][j]==a[i][j])
				{
					ans-=a[i][j];
					break;
				}
			}	
		}
	}
	
	cout<<ans;
}

Measured memory_bytes: 896