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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///


void _case()
{
    string a;
    cin>>a;
    ll ans=0;
    for(auto i:a) ans+=(i-'0');
    if(ans%9==0) cout<<"Yes" el;
    else cout<<"No" el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


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

int main() {
	int r, c, sum = 0,sum2 = 0;
	cin >> r >> c;
	int a[r][c];


	for (int i = 0; i < r; i++) {
		sum = 0;
		for (int j = 0; j < c; j++) {
			cin >> a[i][j];
			cout << a[i][j] << " ";
			sum += a[i][j];
		}
		cout << sum << endl;
	}
	for (int j = 0; j < c; j++) {
		sum = 0;
		for (int i = 0; i < r; i++) {
			sum += a[i][j];
			sum2 += a[i][j];
		}
		cout << sum << " ";
	}
	cout << sum2 << endl;

	return 0;
}

Measured memory_bytes: 1196
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
#define ll long long

int binS_first(int *a, int low, int high, int x);

int cmp(const void *x, const void *y) {
  const int *a = (const int *)x;
  const int *b = (const int *)y;
  if (a[0] == b[0])
    return a[1] - b[1];
  else
    return a[0] - b[0];
}

int main(){
    int n,m,i,j;
    scanf("%d %d",&n,&m);
    int service[m][2];
    for(i=0;i<m;i++) {
        scanf("%d %d",&service[i][0],&service[i][1]);
    }
    qsort(service, m, sizeof(service[0]), cmp);
    int a[m],b[m];
    for(i=0;i<m;i++) {
        a[i]=service[i][0];
        b[i]=service[i][1];
    }
    for(i=0;i<m;i++){
        if(a[i]!=1) break;
        int find=binS_first(a, 0, m-1, b[i]);
        if(find==-1) continue;
        while(find<m && a[find]==b[i]){
            if(b[find]==n){
                printf("POSSIBLE\n");
                return 0;
            }
            find++;
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}

int binS_first(int *a, int low, int high, int x)  {
    if(NULL == a || low > high)return -1;
    int mid;
    while(low<high)//<
    {
        mid=low+((high-low)>>1);
        if(a[mid]<x)// <x
            low=mid+1;
        else // >=x
            high=mid;
    }
    if(a[low] == x)
        return low;
    return -1;
}


Measured memory_bytes: 3324
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int N, W;
int dp[10001];

int main(){
	rep(i, N)dp[i] = -1;
	dp[0] = 0;

	std::cin >> N >> W;
	rep(i, N){
		int v, w;
		std::cin >> v >> w;
		rep(j, 10001){
			if (dp[j] != -1 && j + w < 10001)dp[j + w] = std::max(dp[j + w], dp[j] + v);
		}
	}
	std::cout << *std::max_element(dp, dp + W + 1) << std::endl;
	return 0;
}

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll L = (c*d)/gcd(c,d);
  cout << (b-a+1)-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/L-(a-1)/L) << endl;
  return 0;
}


Measured memory_bytes: 256
c = []
c.append(list(map(int,input().split())))
c.append(list(map(int,input().split())))
c.append(list(map(int,input().split())))
ans = "Yes"
for i in range(3):
    a1 = c[1][i]-c[0][i]
    a2 = c[2][i]-c[1][i]
    a3 = c[i][2]-c[i][1]
    a4 = c[i][1]-c[i][0]
    l = [a1,a2,a3,a4]
    if i == 0:
        p = l
    else:
        if p!=l:
            ans = "No"
print(ans)

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

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

string s[4];

bool is_match[3][60000];

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

    cin >> s[0] >> s[1] >> s[2];
    s[3] = s[0];

    int s_size[4];
    for (int i = 0;i < 4;i++){
        s_size[i] = s[i].size();
    }

    for (int i = 0;i < 3;i++){
        for (int j = 0;j < 60000;j++){
            is_match[i][j] = true;
        }
    }

    for (int t = 0;t < 3;t++){
        for (int i = 1-s_size[t+1];i < s_size[t];i++){
            bool f = true;
            int st_a = max(0,i);
            int st_b = max(0,-i);
            int len = min(s_size[t]-st_a,s_size[t+1]-st_b);
            //cout << "sdfsdwerw" << endl;
            for (int j = 0;j < len;j++){
                char ca = s[t][st_a+j];
                char cb = s[t+1][st_b+j];
                if(ca == '?' || cb == '?')continue;
                if(ca == cb) continue;
                f = false;
                break;
            }
            //cout << f << endl;
            //if(f) cout << t << " " << i << endl;
            is_match[t][30000+i] = f;
        }
    }

    int ans = s[0].size()+s[1].size()+s[2].size();
    //cout << is_match[2][3000-2] << endl;

    for (int i = -4500;i < 4500;i++){
        for (int j = -4500;j < 4500;j++){
            if(i+j < -25000 || i+j > 25000) continue;
            int k = i+j;

            if(is_match[0][i+30000] && is_match[1][j+30000] && is_match[2][30000-k]){
                int max_end = max({s_size[0],i+s_size[1],k+s_size[2]});
                int len = max_end - min({0,i,k});
                //if(k == 2 && i == 4) cout << "Fsfsd" << endl;
                //if(len < 10) cout << len << " " << i << " " << j << " " << k << " " << max_end << " " << min({0,i,k}) << endl;
                ans = min(ans,len);
            }
        }
    }

    cout << ans << endl;

    return 0;

}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n;
	string a,b,c; cin>>n>>a>>b>>c;

	int ans=0;
	rep(i,n) ans+=set<char>{a[i],b[i],c[i]}.size()-1;
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 3608
#abc 114 c
INF=100100100
n,A,B,C=map(int,input().split())
L=[]
for i in range(n):
    l=int(input())
    L.append(l)
def dfs(i,a,b,c):
    #print(i,a,b,c)
    if i==len(L):
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF#a,b,cは1MP消費で長さ-1するのでマイナスになる可能性ある
        #0以上でないと３本あることにならない
        #1本目のa,b,cを選ぶときにdfs内ではMP10消費しているので-30
    ret0=dfs(i+1,a,b,c)
    ret1=dfs(i+1,a+L[i],b,c)+10
    ret2=dfs(i+1,a,b+L[i],c)+10
    ret3=dfs(i+1,a,b,c+L[i])+10

    return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let mut a = vec![0i64; n];
    for x in &mut a {
        *x = sc.ne();
    }
    let sum: i64 = a.iter().fold(0, |acc, &x| acc + x);
    let sumn = {
        let mut r = 0i64;
        for i in 0..n {
            r += i as i64 + 1;
        }
        r
    };
    let mut ok = true;
    if sum % sumn != 0 {
        ok = false;
    }
    let key = sum / sumn;
    let mut cntd = 0;
    for i in 0..n {
        let j = (i + 1) % n;
        let x = a[j] - a[i];
        match x {
            val if val == key => {}
            val if val > 0 => ok = false,
            _ => {
                let d = key - x;
                if d % n as i64 != 0 {
                    ok = false;
                } else {
                    cntd += d / n as i64;
                }
            }
        }
    }
    if cntd != key {
        ok = false;
    }
    println!("{}",
             match ok {
                 true => "YES",
                 _ => "NO",
             });
}
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => panic!("parse error"),
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Measured memory_bytes: 3580
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int value;
		int rowTotal;
		int[] colTotal = new int[c];
		
		for (int i = 0; i < r; i++){
			rowTotal = 0;
			for (int j = 0; j < c; j++){
				value = sc.nextInt();
				System.out.print(value + " ");
				rowTotal += value;
				colTotal[j] += value;
			}
			System.out.println(rowTotal);
		}
		
		rowTotal = 0;
		for (int i = 0; i < c; i++){
			System.out.print(colTotal[i] + " ");
			rowTotal += colTotal[i];
		}
		System.out.println(rowTotal);
	}
}

Measured memory_bytes: 32072
using System;

class Program
{
  public static void Main(string[] args)
  {
    while(true)
    {
      string[] read = Console.ReadLine().Split(' ');
      int[] numbers = new int[2];
      for(int i = 0;i < 2;i++) numbers[i] = int.Parse(read[i]);
      if(numbers[0] == 0 && numbers[1] == 0) break;
      if(numbers[0] <= numbers[1]) Console.WriteLine("{0} {1}",numbers[0],numbers[1]);
      else if(numbers[0] > numbers[1]) Console.WriteLine("{0} {1}",numbers[1],numbers[0]);
    }
  }
}

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

const int MAXN = 3e3 + 5;
const int MOD = 1e9 + 7;

int N, M;
int arr[MAXN];
int dp[MAXN][MAXN], tmp[MAXN][MAXN];

inline int add(int x, int y) {
	x += y;
	if (x >= MOD)
		x -= MOD;
	return x;
}

inline int avg(int x, int y) {
	return (long long)add(x, y) * (MOD + 1) / 2 % MOD;
}

void update(int a, int b) {
	for (int i = 1; i <= N; i++) {
		tmp[a][i] = avg(dp[a][i], dp[b][i]);
		tmp[i][a] = avg(dp[i][a], dp[i][b]);
		tmp[b][i] = avg(dp[b][i], dp[a][i]);
		tmp[i][b] = avg(dp[i][b], dp[i][a]);
	}
	tmp[a][b] = tmp[b][a] = avg(dp[a][b], dp[b][a]);
	
	for (int i = 1; i <= N; i++) {
		dp[a][i] = tmp[a][i];
		dp[i][a] = tmp[i][a];
		dp[b][i] = tmp[b][i];
		dp[i][b] = tmp[i][b];
	}
}

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; i++)
		scanf("%d", arr + i);
	
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
			dp[i][j] = arr[i] > arr[j];
	
	for (int i = 0; i < M; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		update(a, b);
	}
	
	int ans = 0;
	for (int i = 1; i <= N; i++)
		for (int j = i + 1; j <= N; j++)
			ans = add(ans, dp[i][j]);
	
	while (M--)
		ans = add(ans, ans);
		
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 70912
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

// 30min
int main(void){
  long long int ans;
  long long a, b, c, d;
  long long int tmp;

  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);

  // 答え = 総数 - (Cで割りきれる個数＋Dで割りきれる個数
  // - CでもDでも割りきれる個数)←最小公倍数を使って求める
  ans = b - (a - 1);

  ans -= (b / c - (a - 1) / c);
  ans -= (b / d - (a - 1) / d);

  // cとdの最小公倍数
  tmp = lcm(c, d);
  ans += (b / tmp - (a - 1) / tmp);
  
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int D=max(A,max(B,C));
    int ans=D;
    for(int i=0;i<K;i++){
        ans*=2;
    }
    cout << A+B+C-D+ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    mochikoshi = 0
    res = 0
    for a in A:
        p, q = divmod(a + mochikoshi, 2)
        res += p
        if p == 0 and mochikoshi == 1:
            mochikoshi = 0
        else:
            mochikoshi = q
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7076
import java.util.*;

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

        Scanner sc = new Scanner(System.in);

        int first = 0;
        int second = 0;
        int third = 0;
        for (int x = 0; x < 10; x++) {
            int mount = sc.nextInt();
            if ( mount >= first ) {
                third = second;
                second = first;
                first = mount;
            } else if (mount >= second) {
                third = second;
                second = mount;
            } else if (mount > third) {
                third = mount;
            }
        }
        System.out.printf("%d\n%d\n%d\n", first, second, third);
    }
}

Measured memory_bytes: 12000
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
int n;
ll k,sum;
vector <ll>a;
ll  f[200005];
bool chk(ll val)
{
	vector<ll>cnt;
	for (int i = 0; i < n; i++)
	{
		cnt.pb(val / f[i]);
	}
	sort(cnt.begin(), cnt.end());
	ll gg = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - cnt[i] >= 0)
			gg += a[i] - cnt[i];
	}
	if (gg <= k)
		return true;
	return false;
}
void solve()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		a.pb(x);
		sum += a[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> f[i];
	}
	sort(a.begin(), a.end());
	ll lo = 0, hi = 1000000000000000000, mid, ans = 0;;
	while (lo <= hi)
	{
		mid = (lo + hi) / 2;
		if (chk(mid))
		{
			ans = mid;
			hi = mid - 1;
		}
		else
			lo = mid + 1;
	}
	cout << ans;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 7244
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<iomanip>
#include<cassert>
#include<complex>
#include<functional>
#include<list>
#include<cmath>
#include<stack>
#include<assert.h>
#define LL long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define F first
#define S second
using namespace std;
LL n,k;
LL ans;
int main(){
  cin>>n;
  k=1;
  while(n>0){
  	n/=2;
  	ans+=k;
  	k*=2;
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

string S;

int main() {
  cin >> S;

  int res = 0;
  for (int i = 0; i < S.size() / 2; i++)
    if (S[i] != S[S.size() - i - 1])
      res++;
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define div 1000000007
using ll = long long;
using P = pair<int,int>;

int main(){
	ll n;
	cin>>n;
	ll str=1;
	rep(i,n){
		str=str%div*(i+1);
	}
	puts(str%div);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
 int s,w;
  in(s>>w);
  if(w>=s) out("unsafe");
  else out("safe");
  
}


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

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

    int N, K;
    cin >> N >> K;
    vector<int> P(N), C(N);
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        P[i] = p - 1;
    }
    for (int i = 0; i < N; i++) cin >> C[i];
    ll ans = -1e9;
    for (int s = 0; s < N; s++) {
        int i = s;
        ll c = 0;
        vector<ll> score;
        do {
            c += C[i];
            score.push_back(c);
            i = P[i];
        } while (i != s);
        for (int i = 0; i < min((int) score.size(), K); i++) {
            ans = max(ans, score[i]);
            ans = max(ans, score[i] + (K - i - 1) / (int) score.size() * score.back());
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3784
from collections import defaultdict
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
x = inp()
a,b = 0,0
has = False
for i in range(1000):
    for j in range(1000,-1000,-1):
        if i**5 - j**5 == x:
            a,b = i,j
            has = True
            break
    if has:
        break
print(a,b)



Measured memory_bytes: 68136
#include <cstdio>
#include <cmath>
int main() 
{
    int i,h,w,n;
    while (scanf("%d",&n)&&n!=0) {
        int res=0;
        double mindiff=1000000.0;
        for (int j=0; j<n; j++) {
            scanf("%d %d %d",&i,&h,&w);
            double diff=22.0-(double)w/(h*h)*10000;
            if (diff<0) diff*=-1;
            if (diff<mindiff) {
                mindiff=diff;
                res=i;
            }
        }
        printf("%d\n",res);
    }
}

            

Measured memory_bytes: 0
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))

cnt = 0
right = 0
acc = a[0]
xor = a[0]
for left in range(n):
    while right < n:
        if right + 1 >= n or acc + a[right+1] != xor ^ a[right+1]:
            break
        right += 1
        acc += a[right]
        xor ^= a[right]
    if acc == xor:
        # print(left, right, acc, xor, cnt, right - left + 1)
        cnt += (right - left + 1)
    acc -= a[left]
    xor ^= a[left]
print(cnt)


Measured memory_bytes: 77900
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
const lli mod = 998244353;
const lli inf = 1e18;

int main(){
	string s;
	cin >> s;
	if(s=="hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s=="hihihihihi"){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
    return 0;
}

Measured memory_bytes: 256
n=int(input())
*a, =map(int,input().split())
a=[a[i]-(i+1) for i in range(n)]
a=sorted(a)

c1=a[n//2-1]
c2=a[n//2]
ans=float('inf')

for c in [c1,c2]:
    tmp=0
    for i in range(n):
        tmp+=abs(a[i]-c)
    ans=min(ans, tmp)
print(ans)

Measured memory_bytes: 106012
#include <bits/stdc++.h>
#define pp pair<int,int>
#define ppp pair<pp,int>
#define fi first
#define si second
#define N 300100
using namespace std;
int seg[4 * N], lazy[4 * N], v, m;
void build(int l, int h, int pos) {
	if (l == h) {
		seg[pos] = lazy[pos] = 0;
		return;
	}
	int mid = (l + h) / 2;
	build(l, mid, 2 * pos);
	build(mid + 1, h, 2 * pos + 1);
	seg[pos] = lazy[pos] = 0;
}
void update(int l, int h, int x, int y, int pos) {
	if (lazy[pos]) {
		seg[pos] = lazy[pos];
		if (l != h) {
			lazy[2 * pos] = lazy[pos];
			lazy[2 * pos + 1] = lazy[pos];
		}
		lazy[pos] = 0;
	}
	if (h < x || l > y)
		return;
	if (x <= l && h <= y) {
		seg[pos] = v;

		//cout << l << " D " << h << ' ' << x << ' ' << y << ' ' << seg[pos] << endl;
		if (l != h) {
			lazy[2 * pos] = v;
			lazy[2 * pos + 1] = v;
		}
		return;
	}
	int mid = (l + h) / 2;
	update(l, mid, x, y, 2 * pos);
	update(mid + 1, h, x, y, 2 * pos + 1);
	seg[pos] = max(seg[2 * pos], seg[2 * pos + 1]);
//	cout << l << " D " << h << ' ' << seg[pos] << endl;
}
int query( int l, int h, int x, int pos) {
	if (lazy[pos]) {
		seg[pos] = lazy[pos];
		if (l != h) {
			lazy[2 * pos] = lazy[pos];
			lazy[2 * pos + 1] = lazy[pos];
		}
		lazy[pos] = 0;
	}
	if (h < x || l > x)
		return 0;
	if (l == h) {
		return seg[pos];
	}
	int mid = (l + h) / 2;
	int q1 = query(l, mid, x, 2 * pos);
	int q2 = query(mid + 1, h, x, 2 * pos + 1);
	return max(q1, q2);
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	int n, k;
	cin >> n >> k;
	int a[n + 1], dp[n + 1];
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i]++;
		assert(a[i] < N);
	}
	int g[n + 1], s[n + 1];
	for (int i = 1; i <= n; i++) {
		s[i] = query(1, N, a[i], 1);
		v = i;
		update(1, N, a[i], min(N - 1, a[i] + k), 1);
		//	cout << a[i] << " F " << a[i] + k << ' ' << s[i] << endl;
		//	cout << s[i] << ' ';
	}
	//cout << endl;
	build(1, N, 1);
	for (int i = 1; i <= n; i++) {
		g[i] = query(1, N, a[i], 1);
		v = i;
		update(1, N, max(1, a[i] - k), a[i], 1);
	}
	for (int i = 1; i <= n; i++) {
		dp[i] = 1;
		if (s[i])
			dp[i] = max(dp[i], dp[s[i]] + 1);
		if (g[i])
			dp[i] = max(dp[i], dp[g[i]] + 1);
	}
	cout << *max_element(dp + 1, dp + n + 1) << endl;
	return 0;
}

Measured memory_bytes: 16480
#include <stdio.h>
int main(){
  int i,a,b,k;
  scanf("%d%d%d",&a,&b,&k);
  for(i=a;i<=b;i++){
    if(i<a+k || i>=b-k+1)
    printf("%d\n",i);
  }
  return 0;
}


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

int main() {

  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;

  for(int a = 0; a <= A; ++a) {
      for(int b = 0; b <= B; ++b) {
          for(int c = 0; c <= C; ++c) {
              int total = 500 * a + 100 * b + 50 * c;
              if(total == X) ++res;
          }
      }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    s=str(input())
    l=len(s)
    val=s.count('o')
    if val+15-l>=8:
        print('YES')
    else: print('NO')
    
resolve()

Measured memory_bytes: 38416
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N,M; cin >> N >> M;
    int ans=1;
    int a=N;
    for(;;){
        if(M==1) {ans=0; break;} 
        if(N<M){
            N+=(a-1);
            ans++;
        }
        else break;

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res*a;
		a = a*a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////


int main() {
	ll n;
	rd(n);
	if (n % 2 == 0) wrln(n);
	else wrln(2 * n);
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optmize ("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define spIO ios::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
typedef long double ld;
int n, arr[100 + 5];
int main()
{
	spIO;
	while (cin >> n)
	{
		for (int i = 0; i < n; i++)
			cin >> arr[i];
		int sum = 0x7fffffff;
		for (int p = 1, ts; p <= 100; p++)
		{
			ts = 0;
			for (int i = 0; i < n; i++)
				ts += (arr[i] - p) * (arr[i] - p);
			if (ts < sum)
			{
				sum = ts;
				
			}
		}
		cout << sum;
	}
}

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

int N, M;
vector<string> elms;
string text;
bool cors[51][5010];
bool memo[5010][1<<12];

bool dfs(int si, int s, int l){
    if(s == (1<<N)-1) return true;
    if(memo[si][s]) return false;
    
    for(int i=0; i<N; i++) if((s>>i&1) == 0){
        if(cors[i][si] && dfs(si+(int)elms[i].size(), s|(1<<i), l+(int)elms[i].size()))
            return true;
    }
    memo[si][s] = true;
    return false;
}

void solve(){
    memset(cors, 0, sizeof(cors));
    memset(memo, 0, sizeof(memo));
    for(int i=0; i<N; i++){
        string elm = elms[i];
        for(int j=0; j<text.size(); j++){
            if(text.substr(j, elm.size()) == elm)
                cors[i][j] = true;
        }
    }
    int ans = 0;
    for(int i=0; i<text.size(); i++){
        ans += dfs(i, 0, 0);
    }
    cout << ans << endl;
}

int main(){
    while(cin>>N>>M, N|M){
        elms.resize(N);
        for(auto &s: elms) cin >> s;
        text = "";
        for(int i=0; i<M; i++){
            string t; cin >> t;
            text += t;
        }
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 23404
#include "bits/stdc++.h"

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ld = long double;

constexpr int nax = 1000 * 1000 + 105;
constexpr int infty = 1000 * 1000 * 1000 + 5;
constexpr int mod = 1000 * 1000 * 1000 + 7;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x & 1) a++;
    else b++;
  }
  ll ans = 1, ode = 1;
  for (int i = 0; i < n; i++) ans *= 3;
  for (int i = 0; i < b; i++) ode *= 2;
  cout << ans - ode << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Procon {
  public Procon () { }
  static void Main (string[] agrs) {
    new Procon ().Do ();
  }

  Scanner cin;

  public long Calc (long A) {
    long ans = 0;
    long L1 = 1;

    for (int i = 0; i < 40; i++) {
      long loop = L1 << (i + 1);
      long cnt = (A / loop) * (loop / 2);
      cnt += Math.Max (0, (A % loop) - (loop / 2) + 1);
      if (cnt % 2 == 1) {
        ans += (L1 << i);
      }
    }
    return ans;
  }

  public void Do () {
    cin = new Scanner ();
    long a = cin.nextLong ();
    long b = cin.nextLong ();

    Console.WriteLine (Calc (a - 1) ^ Calc (b));
  }
}

class Scanner {
  string[] s;
  int i;
  int max_i;

  public Scanner () {
    s = new string[0];
    max_i = 0;
    i = 0;
  }

  public string nextString () {
    if (i >= s.Length) {
      s = Console.ReadLine ().Split (' ');
      max_i = s.Length;
      i = 0;
      if (max_i == 0) {
        return "";
      }
      return s[i++];
    } else {
      return s[i++];
    }
  }

  public int nextInt () {
    return int.Parse (nextString ());
  }

  public long nextLong () {
    return long.Parse (nextString ());
  }

  public double nextDouble () {
    return double.Parse (nextString ());
  }

  public string[] arrayString () {
    return Console.ReadLine ().Split (' ');
  }

  public int[] arrayInt () {
    string[] str = Console.ReadLine ().Split (' ');
    int[] array = new int[str.Length];
    for (int i = 0; i < str.Length; i++) {
      array[i] = int.Parse (str[i]);
    }
    return array;
  }

  public long[] arrayLong () {
    string[] str = Console.ReadLine ().Split (' ');
    long[] array = new long[str.Length];
    for (int i = 0; i < str.Length; i++) {
      array[i] = long.Parse (str[i]);
    }
    return array;
  }

  public double[] arrayDouble () {
    string[] str = Console.ReadLine ().Split (' ');
    double[] array = new double[str.Length];
    for (int i = 0; i < str.Length; i++) {
      array[i] = double.Parse (str[i]);
    }
    return array;
  }
}

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

int main() {
  int n; cin >> n;
  vector<int> p(n),q(n);
  rep(i,n)  cin >> p[i];
  rep(i,n)  cin >> q[i];
  int ans = 0;
  
  rep(i,n){
    if(p[i] > q[i])  
      ans += p[i] - q[i];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3560
#include <stdio.h>
#include<math.h>
int main(){
    int i , flag=0, count=0,n,j,A;
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d",&A);
        for(j=2; j<=sqrt(A); j++){
            if(A%j==0) flag=1;
        }
        if(flag==0) {
            count++;
            //printf("%d ",A);
        }
        flag=0;
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
int N,K;
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K>>N;
	
	if(K%2==0) {
		FOR(i,N) {
			_P("%d%c",(i==0)?(K/2):K,(i==N-1)?'\n':' ');
		}
		return;
	}
	
	vector<int> V;
	FOR(i,N) V.push_back(K/2+1);
	FOR(i,N/2) {
		if(V.back()==1) V.pop_back();
		else {
			V.back()--;
			while(V.size()<N) V.push_back(K);
		}
	}
	
	FORR(c,V) cout<<c<<" ";
	cout<<endl;
	
	
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Measured memory_bytes: 3568
N,Q = map(int,input().split(' '))
out_put_list = [0] * N
tree_list = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split(' '))
    tree_list[a-1].append(b-1)

for _ in range(Q):
    p,x = map(int,input().split(' '))
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Measured memory_bytes: 47920
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vout(a) erep(qxqxqx,a)std::cout << qxqxqx << ' ';std::cout  << std::endl;
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
//#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 2000000000;
const ll INF64 = 9223372036854775807ll;
//const ll INF64 = 9223372036854775ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
//std::vector<vector<int>> g;
namespace mp = boost::multiprecision;
int main(){
    ll a;
    std::cin >> a;
    string s;
    std::cin >> s;
    string d;
    d.pb(s[0]);
    d.pb(s[2]);
    d.pb(s[3]);
    ll dd=stoi(d);
    mp::cpp_int ans=0;
    ans+=a;
    ans*=dd;
    ans/=100;
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3680
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
As=[0]*(N+1)
for i in range(N):
  As[i+1]=A[i]+As[i]
v=Counter(As).values()
ans=0
for i in v:
  ans+=i*(i-1)//2
print(ans)

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

int main() {
  string A,B;
  cin >> A;
  cin >> B;
  if(A.size() > B.size()){
    cout << "GREATER" << endl;
  }
  else if(A.size() < B.size()){
    cout << "LESS" << endl;
  }
  else if(A.size() == B.size()){
    if(A > B){
      cout << "GREATER" << endl;
    }
    else if(A < B){
      cout << "LESS" << endl;
    }
    else {
      cout << "EQUAL" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoderBeginnerContest096
{
    internal class Q2
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var c = int.Parse(input[2]);

            var k = int.Parse(Console.ReadLine());

            var n = 1;
            int max;
            for (; k > 0; k--) {
                max = Math.Max(Math.Max(a, b), c);

                if (max == a) {
                    a *= 2;
                }
                else if (max == b) {
                    b *= 2;
                }
                else if (max == c) {
                    c *= 2;
                }
            }

            Console.WriteLine(a + b + c);
        }
    }
}


Measured memory_bytes: 13140
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void yn(bool ok){if(ok) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1e18;
const int mx=200005;

//ford-fulkerson

//辺を表す構造体(行先,容量,逆辺(の番号))
struct edge{ll to,cap,rev;};

class FordFulkerson{
public:
    V<V<edge>> G;//グラフの隣接リスト
    V<bool> used;//DFSですでに調べたかのフラグ

    explicit FordFulkerson(ll max_V){
        G.resize(max_V);
        used.resize(max_V);
    }

    //fromからtoへ容量capの辺をグラフに追加
    void add_edge(ll from,ll to,ll cap){
        G[from].push_back((edge){to,cap,(ll)G[to].size()});
        G[to].push_back((edge){from,0LL,(ll)G[from].size()-1});
    }

    //増加パスをDFSで探す
    ll dfs(ll v,ll t,ll f){
        if(v==t) return f;
        used[v]=1;
        for(int i=0;i<(int)G[v].size();i++){
            edge &e=G[v][i];
            if(!used[e.to]&&e.cap>0){
                ll d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    //sからtへの最大流を求める
    ll max_flow(ll s,ll t){
        ll flow=0;
        while(true){
            rep(i,(ll)used.size()) used[i]=0;
            ll f=dfs(s,t,INF);
            if(f==0) return flow;
            flow+=f;
        }
    }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V<ll> a(n),b(n),c(n),d(n);
    rep(i,n) cin>>a[i]>>b[i];
    rep(i,n) cin>>c[i]>>d[i];
    FordFulkerson ff(2*n+2);
    for(int i=1;i<=n;i++){
        ff.add_edge(0,i,1);
        ff.add_edge(i+n,2*n+1,1);
    }
    rep(i,n){
        rep(j,n){
            if(a[i]<c[j]&&b[i]<d[j]){
                ff.add_edge(i+1,j+n+1,1);
            }
        }
    }
    out(ff.max_flow(0,2*n+1));
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2e5 + 5;
int n;
ll t, c, p, ans;

int main() {
    cin >> n >> t;
    cin >> p;
    for (int i = 1; i < n; ++i) {
        cin >> c;
        ans += min(c - p, t);
        p = c;
    }
    cout << ans + t << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(void) {
    int n; cin >> n;
    map<int ,int> mp;
    bool flag = true;
    rep(i, n) {
        int a; cin >> a;
        mp[a]++;
        if(mp[a]==2) flag = false;
    }
    if(flag) cout << "YES";
    else cout << "NO";
}



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

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

vector<int> A(N);
vector<int> B(N-1);
for (int i = 0; i < N-1; i++){
  cin >> B.at(i);  
}

A.at(0) = B.at(0);

for  (int i = 1; i < N-1; i++){
  if (B.at(i-1) >= B.at(i)){
   A.at(i) = B.at(i) ;
  }
  else{
   A.at(i) = B.at(i-1) ;
  }
}

  A.at(N-1) = B.at(N-2);  
  
int ans =0;
for(int i = 0; i < N; i++){
  ans += A.at(i);


}
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 256
n=int(input())
c=[[] for i in range(n+1)]
d={}
for i in range(n-1):
    x,y,z=map(int,input().split())
    c[x].append(y)
    c[y].append(x)
    d[x,y]=z
d[1,1]=0
stack=[1]
parent=[None]*(n+1)
while stack:
    i=stack.pop()
    for j in c[i]:
        if j==parent[i]:
            continue
        parent[j]=i
        d[1,j]=d[1,i]+d[tuple(sorted([i,j]))]
        stack.append(j)
for i in range(1,n+1):
    print(d[1,i]%2)

Measured memory_bytes: 99360
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

ll combi(ll n, ll k) {
  if (n==k||k==0) return 1;
  else return combi(n-1, k-1) + combi(n-1, k);
}

int main() {
  int N, M;
  cin >> N >> M;
  ll ans = 0LL;
  if (2<=N) ans += combi(N, 2);
  if (2<=M) ans += combi(M, 2);
  cout << ans << endl;
}

Measured memory_bytes: 384
<?php
while( fscanf( STDIN, "%d", $n ) ){
  $cnt=0;
  for($a=0;$a<10;$a++){
    $s=$a;
    for($b=0;$b<10;$b++){
      $t=$s+$b;
      for($c=0;$c<10;$c++){
        $u=$t+$c;
        $d=$n-$u;
        if($d<0) continue;
        if($d>9) continue;
        ++$cnt;
      }
    }
  }
  printf("%d\n",$cnt);
}

Measured memory_bytes: 15052
def set(mess) :
  Mess = list(mess.split("0"))
  Ml = len(Mess)
  for i in range(Ml) :
    if("" in Mess) :
      Mess.remove("")
      # Mess 内の1番インデックスの小さい""を削除
    else :
      break
  ML = len(Mess)
  change(Mess, ML)

def change(Mess, ML) :
  one = [".", ",", "!", "?", " "]
  alpha = [chr(i) for i in range(97, 97 + 26)]

  Num = list()
  Cnt = list()
  for i in range(ML) :
    a = list(Mess[i])
    Num.append(a[0])
    Cnt.append(len(a))

  ans = list()
  for i in range(ML) :
    if(Num[i] == "1") :
      ans.append(one[Cnt[i] % 5 - 1])
    elif(Num[i] == "7") :
      ans.append(alpha[(Cnt[i]-1)% 4 + 15])
    elif(Num[i] == "8") :
      ans.append(alpha[(Cnt[i]-1)% 3 + 19])
    elif(Num[i] == "9") :
      ans.append(alpha[(Cnt[i]-1)% 4 + 22])
    else :
      x = 3 * (int(Num[i]) - 2)
      ans.append(alpha[(Cnt[i]-1) % 3 + x])

  for j in range(len(ans)) :
    if(j == len(ans) - 1) :
      print(ans[j])
    else :
      print(ans[j], end = "")

N = int(input())
for i in range(N) :
  mess = input()

  set(mess)



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

using namespace std;

int main()
{
    int a[51],n;
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> a[i];
        int sum=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
            sum=sum+(a[i]*a[j]);
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 256