akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)


// 有向グラフでの閉路検出
// O(V+E)
const int NMAX = 1001010;
vector<int> G[NMAX];
vector<int> status(NMAX, 0);
vector<int> dp(NMAX, -1);
// 0:New, 1:Active, 2:Finished
// Activeは行きがけ順序、Finishedは帰り掛け順序

bool IsAcyclicDFS(int v){
    status[v] = 1;
    for(auto to:G[v]){
        if(status[to] == 1) return false;
        else if(status[to] == 0){
            if(IsAcyclicDFS(to) == false) return false;
        }
    }
    status[v] = 2;
    return true;
}

bool IsAcyclic(){
    for(int i=0; i<NMAX; ++i) status[i] = 0;
    for(int i=0; i<NMAX; ++i){
        if(status[i] == 0){
            if(IsAcyclicDFS(i) == false) return false; 
        }
    }
    return true;
}

int rec(int now){
    if(dp[now] != -1) return dp[now];

    int res = 1;
    for(auto to:G[now]){
        chmax(res, rec(to)+1);
    }
    return dp[now] = res;
}

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

    int n; cin >> n;
    vector< vector<int> > a(n, vector<int>(n-1, 0));
    for(int i=0; i<n; ++i) for(int j=0; j<n-1; ++j) { cin >> a[i][j]; --a[i][j]; }

    for(int i=0; i<n; ++i){
        for(int j=0; j<n-2; ++j){
            int s1 = i, t1 = a[i][j];
            int s2 = i, t2 = a[i][j+1];
            if(s1 > t1) swap(s1, t1);
            if(s2 > t2) swap(s2, t2);
            G[1000*s1 + t1].push_back(1000*s2 + t2);
        }
    }

    if(IsAcyclic() == false){
        cout << -1 <<  endl;
        return 0;
    }

    int ans = 0;
    for(int i=0; i<n; ++i){
        for(int j=i+1; j<n; ++j){
            chmax(ans, rec(1000*i + j));
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 51200
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
int AliceP = 0;
int JobP = 0;
cin >> N;
vector<int> cards(N);
for(int i = 0;i < N;i++){
cin >> cards.at(i);}
sort(cards.begin(), cards.end());
reverse(cards.begin(), cards.end());
for(int i = 0;i < N;i+=2){
AliceP += cards.at(i);}
for(int i = 1;i < N;i+=2){
JobP += cards.at(i);}
cout << AliceP - JobP << endl;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9



int main() {
	string S;
	cin >> S;
	bool flag = true;

	while (!S.empty() && flag) {
		flag = false;

		if (S.size() >= 7) {
			string T;
			for (int i = 7; i > 0; i--) T.push_back(S[S.size() - i]);
			if (T == "dreamer") {
				flag = true;
				S.erase(S.end() - 7, S.end());
			}
		}

		if (S.size() >= 6) {
			string T;
			for (int i = 6; i > 0; i--) T.push_back(S[S.size() - i]);
			if (T == "eraser") {
				flag = true;
				S.erase(S.end() - 6, S.end());
			}
		}

		if (S.size() >= 5) {
			string T;
			for (int i = 5; i > 0; i--) T.push_back(S[S.size() - i]);
			if (T == "dream") {
				flag = true;
				S.erase(S.end() - 5, S.end());
			}
			else if (T == "erase") {
				flag = true;
				S.erase(S.end() - 5, S.end());
			}
		}
	}

	if (S.size() == 0) cout << "YES" << endl;
	else cout << "NO" << endl;


	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    int m=0,q=0;
    for(int i=0;i<n;i++){
        if(a[i]==1) q++;
        else{
            m=max(m,q);
            q=0;
        }
    }
    m=max(m,q);
    cout << m+1 << endl;
    return 0;
}



Measured memory_bytes: 3108
import std.stdio,std.conv,std.string,std.algorithm,std.array;
void main(){
    auto s=readln().chomp().split().map!(to!int);
    int a=s[0],b=s[1],c=s[2];
    if(a+b>=c)
        writeln("Yes");
    else
        writeln("No");
}

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

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < 4; i++){
        if(s[i] == '+') ans++;
        else ans--;
    }

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

Measured memory_bytes: 256
import java.util.Scanner;

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

        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        int[] start = new int[26];
        int[] goal = new int[26];
        boolean isAns = true;

        for (int i = 0; i < 26; i++) {
            start[i] = -1;
            goal[i] = -1;
        }

        for (int i = 0; i < s.length; i++) {
            int a = s[i] - 'a';
            int b = t[i] - 'a';
            if (start[a] != -1 || goal[b] != -1) {
                if (start[a] != b || goal[b] != a) {
                    isAns = false;
                    break;
                }
            }
            start[a] = b;
            goal[b] = a;
        }

        System.out.println(isAns ? "Yes" : "No");
    }
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  ll x; cin >> x;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  vector<ll> B = A;
  ll ans = 1e18, sum = accumulate(ALL(A), 0LL);
  REP(i, N) {
    REP(j, N) {
      if (A[(j+i)%N] < B[j]) {
        sum = sum - B[j] + A[(j+i)%N];
        B[j] = A[(j+i)%N];
      }
    }
    ans = min(ans, sum + (ll)i * x);
  }
  //REP(i, N) cout << A[i] << (i == N-1 ? '\n' : ' ');
  cout << ans << endl;
  return 0;
}


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


def solve(N: int, a: "List[int]"):
    x = [0] * (N+1)
    for i in range(1,N+1):
        x[i] = a[i-1]+x[i-1]

    sum_of = sum(a)
    m = 10000000000000000
    for i in range(1,N):
        m = min(m, abs(sum_of - 2*x[i]))

    print(m)
    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: 33764
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
#define what(x) cerr << #x << " is " << x << endl;
const int INF = 1 << 28;

int main() {
    int N;
    cin >> N;
    vvi edge(N + 1);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vi distF(N + 1, INF);
    vi distS(N + 1, INF);
    distF[1] = 0;
    distS[N] = 0;
    deque<pii> queF; // node, distance
    queF.emplace_back(1, 0);
    while (queF.size()) {
        auto node = queF.front();
        queF.pop_front();
        for (auto n : edge[node.first]) {
            if (distF[n] == INF) {
                distF[n] = node.second + 1;
                queF.emplace_back(n, distF[n]);
            }
        }
    }
    deque<pii> queS; // node, distance
    queS.emplace_back(N, 0);
    while (queS.size()) {
        auto node = queS.front();
        queS.pop_front();
        for (auto n : edge[node.first]) {
            if (distS[n] == INF) {
                distS[n] = node.second + 1;
                queS.emplace_back(n, distS[n]);
            }
        }
    }
    int f(0), s(0);
    for (int i = 2; i < N; ++i) {
        if (distF[i] <= distS[i])
            f++;
        else
            s++;
    }
    if (f > s)
        cout << "Fennec" << endl;
    else
        cout << "Snuke" << endl;
    return 0;
}

Measured memory_bytes: 6656
#include<stdio.h>
#include<stdlib.h>
void insertionSort(int*,int,int*);
void ShellSort(int,int *);
int count = 0;
int temp = 0; 
int temp_temp;
int h[20];
int main(void){
	int num,*arr,i,j;
	scanf("%d",&num);
	arr = (int *)malloc(sizeof(int) * num);
	for(i=0;i<num;i++) scanf("%d",&arr[i]);
	ShellSort(num,arr);
	printf("%d\n",temp_temp+1);
	for(i=temp;i!=-1;i--)  i==0 ? printf("%d\n",h[i]):printf("%d ",h[i]);
	printf("%d\n",count);
	for(i=0;i<num;i++){
		printf("%d\n",arr[i]);
	}
	return 0;
	
}
void ShellSort(int num,int *arr){
	int i,j,n,m;//temp = 0;
	h[0]=1;
	for(i=0;i<20;i++){
		h[i+1] = 3 * h[i] +1;
	//	if(11==i) printf("%d\t%d\n",h[i],i);
     //		printf("%d\n",h[i+1]);
		}
	for(i=0;i<20;i++){
		if(num < h[i]){temp = i-1;break;}
		}
//	printf("%d\n",h[temp]);
/*	for(i=0;i<h[temp];i++){	
		printf("%d!!\n",i);
		insertionSort(arr,num,&h[i]);
	}
*/
	for(i=temp;i!=-1;i--){
		if(i==temp){/*printf("%d\n",temp+1);*/temp_temp = temp;}
		//i==0 ? printf("%d\n",h[i]):printf("%d ",h[i]);
		insertionSort(arr,num,&h[i]);
	}
}
void insertionSort(int *arr,int num,int *h){
	int i,j,v;
//	printf("!%d\n",*h);
//	printf("!!\n");
	for(i=(*h);i<num;i++){
	//	printf("%d\n",i);
	//	printf("%d\n",arr[i]);
		v = arr[i];
		j = i - (*h);
	//	printf("!!\n");
		while(j >= 0 && arr[j] > v){
			arr[j+(*h)] = arr[j];
			j = j - (*h);
			count++;
	//		printf("!!\n");
		}
		arr[j+(*h)] = v;	
	//		printf("abc\n");
	}
}

Measured memory_bytes: 4508
n=int(input())
l=[]
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        if n//i==i:
            l.append(max(len(str(i)),len(str(i))))
            break
        else:
            l.append(max(len(str(i)),len(str(n//i))))
print(min(l))

Measured memory_bytes: 3188
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    
    long H[] = new long[N]; 
    for(int i=0; i<N; i++){
      H[i] = sc.nextInt();
    }
    Arrays.sort(H);
    
    long num = 0;
    if(K >= N){
      System.out.println(0);
    }
    else{
      for(int i=0; i< N-K; i++){
        num += H[i];
      }
      System.out.println(num);
    }
    
  }
}

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

int main(){
	ll n; cin >> n;
	vl a(n); rep(i,n)cin >> a[i];
	while(true){
		sort(a.begin(), a.end());
		if(a[n-2] == 0)break;
		rep(i,n){
			if(a[i] != 0){
				for(ll j = i+1;j<n;j++)a[j] %= a[i];
				break;
			}
		}
	}
	cout << a[n-1] << endl;
}

Measured memory_bytes: 1024
"""
最大公約数を求める
"""
def gcd(a, b):
    while (a != 0 and b != 0):
        if (a >= b):
            a = a % b
        else:
            b = b % a
    return a+b

if __name__ == '__main__':
    x, y = map(int, input().split())
    print(gcd(x,y))



Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  string S;
  cin >> S;
  string ans ="Good";
  
  if (S[0] == S[1]){
    ans = "Bad";
  }
  if (S[1] == S[2]){
    ans = "Bad";
  }
  if (S[2] == S[3]){
    ans = "Bad";
  }
  
  cout << ans << endl;
  return 0;
}
    


Measured memory_bytes: 256
ans = []

def gcd(a, b) :
    if a % b == 0 :
        return b
    else :
        return gcd(b, a % b)
        
def lcm(a, b) :
    return a * b // gcd(a, b)

while True :
    try :
        s = input()
        a, b = map(int, s.split())  
        m_gcd, m_lcm = gcd(a, b), lcm(a, b)
        ans.append([m_gcd, m_lcm])
    except :
        for a in ans :
            print(a[0], a[1])
        break



Measured memory_bytes: 5592
#include <iostream>
using namespace std;
long long a[3000],b[3000];
int main(){
	long long ans=1234123412341234,x,ans0=0;int n;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		cin>>a[i];b[i]=a[i];ans0+=a[i];
	}
	for(int i=1;i<=n;i++){
		if(ans>ans0)ans=ans0;
		ans0+=x;
		for(int j=0;j<n;j++){
			int k=j-i;
			while(k<0)k+=n;
			if(b[j]>a[k]){
				ans0-=(b[j]-a[k]);
				b[j]=a[k];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($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;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn f(a: i64, b: i64) -> usize {
    if a.to_string().len() < b.to_string().len() {
        b.to_string().len()
    } else {
        a.to_string().len()
    }
}

fn main() {
    let n = scan!(i64);

    let sq = (n as f64).sqrt() as i64 + 2;

    let mut num = 1 << 60;
    for i in 1..sq {
        if n % i == 0 {
            num = min(num, f(i, n / i))
        }
    }

    println!("{}", num);
}


Measured memory_bytes: 4352
n,m=map(int,input().split())

N=[]

for i in range(n):
    N.append([0,0])

co=0
pe=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=='WA':
        N[p-1][0]+=1
    elif N[p-1][1]!=1:
        pe+=N[p-1][0]
        co+=1
        N[p-1][1]=1

print(str(co)+' '+str(pe))

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

int main() {
    /*
cout<<"Hello World"<<endl;

    int x;
    cin>> x;
    cout<< x*x*x <<endl;

int a;
int b;
cin>>a>>b;
cout<<a*b<<" "<<2*a+2*b<<endl;

    int a;
    int b;
    cin>>a>>b;
    if (a<b){
        cout<< "a < b" <<endl;
    }else if(a>b){
        cout<<"a > b" <<endl;
    }else if(a==b){
        cout<<"a == b"<<endl;
    }else{

    }
    int a;
    int b;
    int c;
    cin>>a>>b>>c;
    if (a<b&&b<c){
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }

    int a;
    int b;
    int c;
    int d;
    cin>>a>>b>>c;
    if(a>b){
    d=b;
    b=a;
    a=d;
    }
    if(b>c){
    d=c;
    c=b;
    b=d;
    }
    if(a>b){
    d=b;
    b=a;
    a=d;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;

    int W;
    int H;
    int x;
    int y;
    int r;
    int f1;
    int f2;
    int f3;
    int f4;
    cin>>W>>H>>x>>y>>r;

    bool t = false;

    if (x-r>=0){
        if(t) cout<<"1Yes"<<endl;
        f1=1;
    }else if (x-r<0){
        if(t) cout<<"1No"<<endl;
        f1=0;
    }
    if (y+r<=H){
        if(t) cout<<"2Yes"<<endl;
        f2=1;
    }else if (y+r>H){
        if(t) cout<<"2No"<<endl;
        f2=0;
    }
    if (x+r<=W){
        if(t) cout<<"3Yes"<<endl;
        f3=1;
    }else if (x+r>W){
        if(t) cout<<"3No"<<endl;
        f3=0;
    }
    if (y-r>=0){
        if(t) cout<<"4Yes"<<endl;
        f4=1;
    }else if (y-r<0){
        if(t) cout<<"4No"<<endl;
        f4=0;
    }
    if (f1==1&&f2==1&&f3==1&&f3==1&&f4==1){
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }

    int i;

    for (i=1;i<=1000;i++){
        cout<<"Hello World"<<endl;
    }

	int x;
	int y;
	//int a[10];
	//int b[10];
	while (1){
		cin>>x>>y;
		if(x==0&&y==0){
			break;
		}
		else if(x<y){
			cout<<x<<" "<<y<<endl;
		}else{
			cout<<y<<" "<<x<<endl;
		}

	}



	int a[10];

	for(int i=0; i<10;i++){
		a[i]=0;
	}
	for(int i=0; i<10;i++){
		cout<<a[i]<<endl;
	}
*/

	int n;
	int b;
	int f;
	int r;
	int v;
	int a[4][3][10];
	//cin>>n>>b>>f>>r>>v;
	for (int i=0;i<4;i++){
		for (int j=0;j<3;j++){
			for (int k=0;k<10;k++){
				a[i][j][k]=0;
			}
		}
	}
	cin>>n;
	for(int i=0;i<n;i++){
	cin>>b>>f>>r>>v;
	a[b-1][f-1][r-1]+=v;
	}




	for (int i=0;i<4;i++){
		for (int j=0;j<3;j++){
			for (int k=0;k<10;k++){
				cout<<" "<<a[i][j][k];
			}
			cout<<endl;
		}
		if(i<3){
			cout<<"####################"<<endl;
		}
	}












    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    if(n%2==0) cout << n << endl;
    else cout << 2*n << endl;
}

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

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

using Graph=vector<vector<tuple<ll,ll,ll>>>;

int main(){
    ll N,M,s,t;
    cin>>N>>M>>s>>t;
    s--;
    t--;

    Graph G(N);
    REP(i,M){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;
        v--;
        G[u].push_back(make_tuple(v,a,b));
        G[v].push_back(make_tuple(u,a,b));
    }

    vector<ll> dist_s(N,INF),dist_t(N,INF);

    //ダイクストラ
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> que;
    
    // 初期条件 (頂点 0 を初期ノードとする)
    dist_s[s] = 0;
    que.push(make_pair(0,s)); // 0 を橙色頂点にする
    
     // 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        pair<ll,ll> p = que.top(); // 優先度キューから先頭頂点を取り出す
        que.pop();
        ll d=p.first;
        ll v=p.second;
        if(dist_s[v]<d) continue;
        // v から辿れる頂点をすべて調べる
        for (auto nG : G[v]) {
            ll nv=get<0>(nG);
            ll cost=get<1>(nG);
            ll nd=d+cost;
    
            // 新たな頂点 nv について距離が短いなら更新
            if(nd<dist_s[nv]){
                dist_s[nv] = nd;
                que.push(make_pair(nd,nv));
            }
        }
    }

     // 初期条件 (頂点 0 を初期ノードとする)
    dist_t[t] = 0;
    que.push(make_pair(0,t)); // 0 を橙色頂点にする
    
     // 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        pair<ll,ll> p = que.top(); // 優先度キューから先頭頂点を取り出す
        que.pop();
        ll d=p.first;
        ll v=p.second;
        if(dist_t[v]<d) continue;
        // v から辿れる頂点をすべて調べる
        for (auto nG : G[v]) {
            ll nv=get<0>(nG);
            ll cost=get<2>(nG);
            ll nd=d+cost;
    
            // 新たな頂点 nv について距離が短いなら更新
            if(nd<dist_t[nv]){
                dist_t[nv] = nd;
                que.push(make_pair(nd,nv));
            }
        }
    }

    ll tot=pow(10,15);

    vector<pair<ll,ll>> ans(N);
    REP(i,N){
        ll lose=dist_s[i]+dist_t[i];
        ll money=tot-lose;
        ans[i]=make_pair(money,i+1);
    }

    sort(ALL(ans),greater<pair<ll,ll>>());

    ll cnt=0;
    REP(i,N){
        while(ans[cnt].second<=i) cnt++;
        cout<<ans[cnt].first<<endl;
    }


}

Measured memory_bytes: 15772
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <vector>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool neg=c=='-';
	neg?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return neg?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
template<class T>inline void mset(T a,int v,int n){memset(a,v,n*sizeof(a[0]));}
const int N=310,D=200010;
struct Pt{
	int x,y;
};
bool vis[N<<1][N<<1];
vector<Pt>ban,lst[4];
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
int n;
inline bool valid(int x,int y){
	return x>=0&&x<n*2&&y>=0&&y<n*2;
}
int col[N<<1][N<<1];
void dfs(int x,int y,int c,int bt){
	assert(!vis[x][y]);
	vis[x][y]=true;
	col[x][y]|=c;
	for(vector<Pt>::iterator it=ban.begin(),ti=ban.end();it!=ti;++it){
		const int tx=x+it->x,ty=y+it->y;
		if(valid(tx,ty)){
			if(vis[tx][ty]){
			}else{
				dfs(tx,ty,c^bt,bt);
			}
		}
	}
}
int issqr[D];
inline void work(int d1,int btmask){
	ban.clear();
	for(int i=0;i*i<=d1;i++){
		int j=issqr[d1-i*i];
		if(j!=-1){
			ban.push_back((Pt){i,j});
			ban.push_back((Pt){i,-j});
			ban.push_back((Pt){-i,j});
			ban.push_back((Pt){-i,-j});
			if(i!=j){
				ban.push_back((Pt){j,i});
				ban.push_back((Pt){j,-i});
				ban.push_back((Pt){-j,i});
				ban.push_back((Pt){j,-i});
			}
		}
	}
	for(int i=0;i<n*2;i++){
		mset(vis[i],0,n*2);
	}
	for(int i=0;i<n*2;i++){
		for(int j=0;j<n*2;j++){
			if(!vis[i][j]){
				dfs(i,j,0,btmask);
			}
		}
	}
}
int main(){
	n=ni;
	const int d1=ni,d2=ni;
	memset(issqr,-1,sizeof(issqr));
	for(int i=0;i*i<=d1||i*i<=d2;i++){
		issqr[i*i]=i;
	}
	work(d1,1),work(d2,2);
	for(int i=0;i<n*2;i++){
		for(int j=0;j<n*2;j++){
			lst[col[i][j]].push_back((Pt){i,j});
		}
	}
	int mxp=0;
	for(int i=1;i<4;i++){
		if(lst[i].size()>lst[mxp].size()){
			mxp=i;
		}
	}
	assert(lst[mxp].size()>=(unsigned)n*n);
	for(int i=0;i<n*n;i++){
		printf("%d %d\n",lst[mxp][i].x,lst[mxp][i].y);
	}
	return 0;
}


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

int main(void) {
    string S;

    cin >> S;

    for (int i=0; i<S.length(); i++) {
        if((i+1)%2 == 1) {
            if(S[i] != 'R' && S[i] != 'U' && S[i] != 'D' ) {
                cout << "No" << endl;
                return 0;
            }
        }else {
            if(S[i] != 'L' && S[i] != 'U' && S[i] != 'D' ) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e6+16;
const ll INF=100000000000005;
const double eps=1e-11;
using namespace std;
ll n,m,p;
map<ll,ll>mp;
ll sum[maxn];
ll num[maxn];
int main()
{
    ll res=0;//记录最终答案
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&num[i]);
        sum[i]=sum[i-1]+num[i];
    }
    for(int i=1;i<=n;i++)
        sum[i]=(sum[i]-i%m+m)%m;//预处理前缀和
    ll low=min(m-1,n);
    for(int i=0;i<=low;i++)
    {
        res+=mp[sum[i]];
        mp[sum[i]]++;
    }
    for(int i=low+1;i<=n;i++)
    {
        mp[sum[i-m]]--;
        res+=mp[sum[i]];
        mp[sum[i]]++;
    }
    printf("%lld\n",res);
    return 0;
}


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

int main() {
  int n, t, a;
  std::cin >> n >> t >> a;

  double min_abs = 200000;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int height;
    std::cin >> height;
    double avg_temp = t - height * 0.006;
    if (min_abs > fabs(avg_temp - a)) {
      min_abs = fabs(avg_temp - a);
      ans = i + 1;
    };
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>


using namespace std;

int main(){

	long N, M, max;

	long ans = 1;

	cin >> N >> M;

	max = M/N;

	for(long i = max; i > 0; i--){
		if(M % i == 0){
		 	ans = i;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template <typename X>
struct Node{
  int idx;
  int par;
  X depth;
  
  Node() = default;

  explicit Node(int idx) : idx(idx) {}

};
template <typename X>
struct Edge{
  int from;
  int to;
  X cost;

  Edge() = default;

  Edge(int from, int to, X cost) : from(from), to(to), cost(cost) {}
};
template <typename X>
class Tree{
private:
  int n; // number of node
  vector<vector<Edge<X>>> edge; 
  vector<Node<X>> node;
  
  const int MAXLOGN = 20;
  
public:
  Tree() = default;

  Tree(int n) : n(n) {
    edge.resize(n);
  }

  Tree(int n, vector<int> a, vector<int> b) : n(n) {
    edge.resize(n);
    rep(i,n-1) {
      add_edge(a[i], b[i]);
      add_edge(b[i], a[i]);  // indirected edge
    }
  }

  Tree(int n, vector<int> a, vector<int> b, vector<X> c) : n(n) {
    edge.resize(n);
    rep(i,n-1) {
      add_edge(a[i], b[i], c[i]);
      add_edge(b[i], a[i], c[i]);  // indirected edge
    }
  }  

  void add_edge(int from, int to, X cost = 1) {
    edge[from].emplace_back(from, to, cost);
  }

  void DFS_Init(int v, int p, X d) {
    node[v].par = p;
    node[v].depth = d;
    for(auto next: edge[v]) {
      int w = next.to;
      X cost = next.cost;
      if(w == p) continue;
      DFS_Init(w, v, d + cost);
    }
  }

  void Init_Node(int root) {
    rep(i,n) node.emplace_back(i);
    DFS_Init(root, -1, 0);
  }

  X Diameter() {
    X res = 0;
    int farpoint = 0;
    Init_Node(0);
    rep(i,n) {
      if(chmax(res, node[i].depth)) {
	farpoint = i;
      }
    }
    Init_Node(farpoint);
    res = 0;
    rep(i,n) chmax(res, node[i].depth);
    return res;
  }
  
};

int main()
{
  int n;cin >> n;
  vector<int> a(n-1), b(n-1), c(n-1);
  rep(i,n-1) {
    cin >> a[i] >> b[i] >> c[i];
  }
  
  Tree<int> tr(n, a, b, c);
  cout << tr.Diameter() << "\n";
  
  return 0;
}



Measured memory_bytes: 15372
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

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


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
//#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, b) for( int i = 0; i < b; i++ )
#define m_t 60
#define max (3*m_t*(m_t+1)+1)
#define zero (max/2)
#define mp make_pair

int dx[6] = {0,1,-1,1,-1,0};
int dy[6] = {1,1,0,0,-1,-1};
vector<int> field(max);
int t, n;
int cnt;

int main(){
    while( cin >> t >> n, t ){
        fill( field.begin(), field.end(), 1 );  // reset
        int x, y;
        /* input of obstacle */
        rep(i, n){
            cin >> x >> y;
            y = y * (m_t*2 + m_t*2+1-abs(y)) / 2;
            field[zero+x+y] = 0;
        }
        int sx, sy;
        /* input of the starting point */
        cin >> sx >> sy;
        x = sx;
        y = sy * (m_t*2 + m_t*2+1-abs(sy)) / 2;
        field[zero+x+y] = 0;
        //cnt = 0;
        //dfs(sx, sy, 0);

        int ans = 0;
        queue< pair< pair<int, int>, int > > rt;
        rt.push(mp(mp(sx, sy), 0));

        while( !rt.empty() ){
            ans++;
            int cx = rt.front().first.first;
            int cy = rt.front().first.second;
            int ct = rt.front().second;
            rt.pop();

            if( ct < t ){
                rep(i, 6){
                    int nx = cx + dx[i];
                    int ny = (cy + dy[i]) * (m_t*2 + m_t*2+1-abs(cy+dy[i])) / 2;
                    if( field[zero+nx+ny] ){
                        field[zero+nx+ny] = 0;
                        rt.push(mp(mp(nx, cy+dy[i]), ct+1));
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1264
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

int gcd(int a, int b){
    while( b ){
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

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

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //xのn乗を計算するのにn乗を2進表記にして計算
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//答えに付加
        }
        x=(x*x)%mod;//2乗
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    long long min=0;
    long long kake=0;
};

class xxIntu {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第1条件
        if(riLeft.kake != riRight.kake){
            return riLeft.kake > riRight.kake;//<:昇順(小さい順)、>:降順(大きい順)
        }
        //第2条件
        return riLeft.min > riRight.min;
    }
};
bool operator< (const VV &riLeft, const VV &riRight){
    return riLeft.z < riRight.z;
};
/*bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};*/



int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //テスト用
    //ifstream ifs( "1_06.txt" );
    //ifs >> a;
    //ここから

    int a,b,h;
    cin >> a >> b >>h;
    int ans=(a+b)*h/2;
    

    cout << ans << endl;
    

    
    //cout << "ans" << endl;
    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h> 
#include <stdlib.h>

int main()
{
	int x, y, w, h, r;
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	if(x + r <= w &&y + r <= h &&y - r >= 0&&x - r >= 0)
	{
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}



Measured memory_bytes: 2096
#include <bits/stdc++.h>
#include <iostream>
#include <string> 
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  if(A>B){
    cout << "a > b" << endl;
  }
  else if(A==B){
    cout << "a == b" << endl;
  }
  else if(A<B){
    cout << "a < b" << endl;
  }
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
string s;
int main()
{
	int o=0;
	cin>>s;
	for(int i=0;i<6;++i)
		if(s[i]=='1') o++;
	cout<<o<<endl;
	return 0;
} 

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		if(N/10==9)
			System.out.println("Yes");
		else
			if(N%10==9)
				System.out.println("Yes");
			else
				System.out.println("No");
	}
}

Measured memory_bytes: 21716
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mods[] = {998244353, 1000000007, 1000000009};
const ll bases[] = {997, 1009, 1013};
const ll mod = mods[0];
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll powl(ll x,ll r,ll mod){
  ll ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

ll n;
vl d;
vl cnt;
ll ans = 1;

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

  if(d[0] != 0){
    cout << 0 << endl;
    return 0;
  }
  cnt = vl(2*n, 0ll);
  cnt[0] = 1;
  for(ll i = 1;i < n;i++){
    if(d[i] == 0){
      cout << 0 << endl;
      return 0;
    }
    cnt[d[i]]++;
  }
  for(ll i = 1;i <= n;i++){
    ans *= powl(cnt[i-1],cnt[i],mod);
    ans %= mod;
  }
  cout << ans << endl;


}


Measured memory_bytes: 2560
import copy

class Card:
    def __init__(self, suit, number):
        self.suit = suit
        self.number = number

    def equals(self, card):
        if (card.suit == self.suit) and (card.number == self.number):
            return True
        else:
            return False

def bubble_sort(cards, n):
    for i in range(n):
        for j in range(n - 1, i, -1):
            if cards[j - 1].number > cards[j].number:
                cards[j - 1], cards[j] = cards[j], cards[j - 1]
    return cards

def selection_sort(cards, n):
    for i in range(n):
        min_j = i
        for j in range(i, n):
            if cards[j].number < cards[min_j].number:
                min_j = j
        if min_j != i:
            cards[i], cards[min_j] = cards[min_j], cards[i]
    return cards

def is_stable(cards1, cards2, n):
    result = True
    for i in range(n):
        if not(cards1[i].equals(cards2[i])):
            result = False
            break
    return result

def print_cards(cards, n):
    print(' '.join([c.suit + str(c.number) for c in cards]))

n = int(input())
cards = [Card(card[0], int(card[1])) for card in input().split()]
cards_bubble = bubble_sort(copy.deepcopy(cards), n)
cards_selection = selection_sort(copy.deepcopy(cards), n)

print_cards(cards_bubble, n)
print('Stable')
print_cards(cards_selection, n)
if is_stable(cards_bubble, cards_selection, n):
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 6352
#include <bits/stdc++.h>
  
using namespace std;
  
int main(){
  int n, m;
  
  while(scanf("%d%d" ,&n ,&m), (n | m)){
    int N = n+m, arr[N];
    for(int i = 0 ; i < N ; i++){
      scanf("%d" ,arr+i);
    }
    sort(arr, arr+N);
  
    int max = arr[0];
    for(int i = 0 ; i < N ; i++){
      max = std::max(max, arr[i] - arr[i-1]);
    }
    printf("%d\n" ,max);
  }
  
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int N; cin>>N;
    MP mp;
    ll sum=0; mp[0]++;
    rep(i,N){
        ll A; cin>>A;
        sum+=A;
        mp[sum]++;
    }
    ll ans=0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        ans+=itr->second*(itr->second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long LL;
typedef long double LD;
#define MAXN 1000
#define MOD 761238923

int A[3];

int main() {
#ifdef OJ
    //freopen("input.txt", "rt", stdin);
    //    freopen("output.txt", "wt", stdout);
#endif
    std::ios_base::sync_with_stdio(false);

    for(int i = 0; i < 3; i++)
        scanf("%d", &A[i]);

    sort(A,A+3);

    int d13 = A[2] - A[0];
    int d23 = A[2] - A[1];

    int ans = 0;

    ans += d13/2 + d23/2;
    d13 %= 2;
    d23 %= 2;

    if (d13 && d23) {
        ans++;
    } else if (d13 || d23) {
        ans += 2;
    }

    printf("%d\n",ans);
        
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
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 all(a)  (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vll vector<ll>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
const ll INF =1LL << 62;
int main(){
  int N; cin >> N;
  vector<int> H(N);
  cinf(N,H);
  int ans=0;
  int max=H[0];
  rep(i,N){
    if(max <= H[i]) ans ++;
    chmax(max,H[i]);
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = (0); (i) < (n); (i)++)
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

int main(){
  //string s;
  char s;
  cin >> s;
  cout << char(s + 1) << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "c")cout << "b" << endl;
  //if(s == "d")cout << "b" << endl;
  //if(s == "e")cout << "b" << endl;
  //if(s == "f")cout << "b" << endl;
  //if(s == "g")cout << "b" << endl;
  //if(s == "h")cout << "b" << endl;
  //if(s == "i")cout << "b" << endl;
  //if(s == "j")cout << "b" << endl;
  //if(s == "k")cout << "b" << endl;
  //if(s == "l")cout << "b" << endl;
  //if(s == "r")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
  //if(s == "a")cout << "b" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 3
#define N2 9
#define MAX 100 
#define true 1
#define false -1

int puzzle[N][N];
int tmp[N][N];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void swap(int *a,int *b) {
  int tmp;
  tmp=*a;
  *a=*b;
  *b=tmp;
}

int ca() {
  int i,k,sum=0;
  for(i=0;i<N2;i++) {
    if((k=puzzle[i/3][i%3])) {
      k--;
      sum+=abs(i/3-k/3)+abs(i%3-k%3);
    }
  }
  return sum;
}

int DFS(int x,int y,int p,int dep,const int lim) {
  int i,h,tx,ty,res,j;
  h=ca();
  if(h==0) return dep;
  if(dep+h>lim){
    return false;
  }
  for(i=0;i<4;i++) {
    tx=x+dx[i];
    ty=y+dy[i];
    if(~p && i==(p+2)%4) continue;
    if(!(0<=tx && tx<3 && 0<=ty && ty<3))continue;
    swap(&puzzle[y][x],&puzzle[ty][tx]);
    res=DFS(tx,ty,i,dep+1,lim);
    if(~res)return res;
    swap(&puzzle[y][x],&puzzle[ty][tx]);
  }
  
  return false;
}

int main(){
  int i,j,c,k;
  int x,y,r;
  
  for(i=0;i<N;i++) {
    for(j=0;j<N;j++){
      scanf("%d",&puzzle[i][j]);
      if(!puzzle[i][j]){
	x=j;
	y=i;
      }
    }
  }
  
  for(k=0;k<MAX;k++) {
    memcpy(tmp,puzzle,sizeof(puzzle));
    c=DFS(x,y,false,0,k);
    if(c!=false)
      break;
    memcpy(puzzle,tmp,sizeof(tmp));
  }

  printf("%d\n",c);
  
  return 0;
}




Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int N;
int A, B;
ll v[52];
ll ave;
ll com[52][52];
ll ans;
  
int main() {
  
  com[0][0] = 1;
  for(int i = 0; i < 52; i++){
    com[i][i] = com[i][0] = 1;
  }
  
  for(int i = 1; i < 52; i++){
    for(int j = 1; j < i; j++){
      com[i][j] = com[i-1][j-1] + com[i-1][j];
    }
  }
  
  cin >> N >> A >> B;

  for(int i = 0; i < N; i++) {
    cin >> v[i];
  }

  sort(v,v+N,greater<ll>());
  
  for(int i = 0; i < A; i++){
    ave += v[i];
  }
  
  cout << fixed << ave / (double)A << endl;

  int k = 0; int t = 0;
  for(int i = 0; i < N; i++){
    if(v[i] == v[A-1]){
      k++;
      if(i < A){
	t++;
      }
    }
  }

  if(t == A){
    for(int i = A; i <= B; i++){
      ans += com[k][i];
    }
  }
  else {
    ans += com[k][t];
      }
     cout << ans <<endl;
 
   

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
typedef long long ll;
ll cnt[maxn],dp[maxn];
void init()
{
    memset(cnt,0,sizeof(cnt));
}
signed main()
{
    ll x;
    while(~scanf("%lld",&x))
    {
        ll a=x/500;
        x-=(a*500);
        printf("%lld\n",a*1000+x/5*5);
    }
    return 0;
}

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

string a = "kstnhmyr";
int main() {
	string d;
	cin >> d;
	for (int e = 0; e < d.length(); e+=2) {
		if (d[e] =='0') {
			switch (d[e + 1]) {
			case 'T':cout << "wa"; break;
			case 'D':cout << "wo"; break;
			case 'U':cout << "nn"; break;
			}
			continue;
		}
		if (d[e] != '1')cout << a[d[e] - 50];
		switch (d[e + 1]) {
		case 'T':cout << 'a'; break;
		case 'U':cout << 'u'; break;
		case 'D':cout << 'o'; break;
		case 'R':cout << 'e'; break;
		case 'L':cout << 'i'; break;
		}
	}
	cout << endl;
}

Measured memory_bytes: 3160
#include<iostream>
    #define rep(i,from,to) for(int i=from;i<to;i++)
    using namespace std;
    int main(){
    	int n;
    	cin>>n;
        rep(i,1,10){
    		int p=n/i;
        	if(p*i==n&&p<=9)return cout<<"Yes"<<endl,0;
      	}
      	cout<<"No"<<endl;
        return 0;
    }

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

int main()
{
    int p,q,r;
    int ans;
    cin>>p>>q>>r;
    if(p+q<q+r)
    {
        ans=p+q;
    }
    else
    {
        ans=q+r;
    }
    if(ans>r+p)
    {
        ans=r+p;
    }

    cout<<ans<<endl;
    
}

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

typedef pair<long long int,int> ii;

int main() {
	
	int n, m, a, b;
	vector<ii> tiendas;

	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		tiendas.push_back(ii(a, b));
	}
	sort(tiendas.begin(), tiendas.end());
	long long int ans = 0;
	for (int i = 0; i < tiendas.size() && m > 0; i++) {
		int bebidas = min(m, tiendas[i].second);
		ans += bebidas * tiendas[i].first;
		m -= bebidas;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

ll gcd(ll x, ll y){
    if(y == 0)return x;
    return gcd(y,x%y);
}

ll lcm(ll x, ll y){
    return x/gcd(x,y)*y;
}

int main()  {
    ll x,y;
    cin>>x>>y;
    if(gcd(x,y) == y){
        cout<<-1;
        return 0;
    }
    int j =0;
    for(ll i=x ;j <=1e7&& i <= 1e18 ; i+=x){
        if(y%i != 0){
            cout<<i;
            return 0;
        }
        j++;
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256