akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

int main(){

    int h, w, k;
    cin >> h >> w >> k;

    vector<string> v(h);
    for(int i = 0; i < h; i++){
        cin >> v[i];
    }
    int ans = 0;
    for(int i = 0; i < (1<<h); i++){
        for(int j = 0; j < (1<<w); j++){
            int sum = 0;
            for(int s = 0; s < h; s++){
                for(int t = 0; t < w; t++){
                    if(i & (1<<s)){
                        if(j & (1<<t)){
                            if(v[s][t] == '#') sum++;
                        }
                    }
                }
            }
            if(k == sum) ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3612
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, W;
  cin >> N >> W;
  vector<int64_t> values(1e5L + 1, 0);
  int64_t result = 0;
  for (int64_t i = 0; i < N; ++i) {
    int64_t w, v;
    cin >> w >> v;
    for (int64_t next_cap = 0; next_cap <= W; ++next_cap) {
      const int64_t current_cap = next_cap + w;
      if (current_cap <= W) {
        values[next_cap] = max(values[next_cap], values[current_cap] + v);
        result = max(result, values[next_cap]);
      }
    }
  }
  cout << result << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, M; scanf("%d %d", &N, &M);
  vector<pair<pair<int, int>, ll>> edges(M);
  int a, b, c;
  for (int i = 0; i < M; ++i) {
    scanf("%d %d %d", &a, &b, &c);
    edges[i] = make_pair(make_pair(a, b), c);
  }
  ll LLMIN = -1 * (ll)1e18;
  vector<ll> dist(N + 5, LLMIN);
  dist[1] = 0;
  for (int i = 0; i < N - 1; ++i) {
    for (int j = 0; j < M; ++j) {
      int u = edges[j].first.first, v = edges[j].first.second;
      ll cost = edges[j].second;
      if (dist[u] != LLMIN and dist[v] < dist[u] + cost) {
        dist[v] = dist[u] + cost;
      }
    }
  }

  ll ans = dist[N];
  for (int k = 0; k < N - 1; ++k) {
    for (int i = 0; i < M; ++i) {
      int u = edges[i].first.first, v = edges[i].first.second;
      ll cost = edges[i].second;
      if (dist[u] != LLMIN and dist[v] < dist[u] + cost) {
        dist[v] = dist[u] + cost;
      }
    }
  }
  if (ans != dist[N]) { printf("inf\n"); }
  else { printf("%lld\n", ans); }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define maxn 3003
using namespace std;
int a[maxn], dp[maxn][maxn], inv[maxn], coef[maxn], ans[maxn];
int main(){
    int p;
    cin >> p;
    for (int i = 0; i < p; ++ i)
        cin >> a[i];
    dp[0][1] = 1;
    for (int i = 1; i < p; ++ i)
        for (int j = 0; j <= p; ++ j){
            dp[i][j] = (p - 1LL * dp[i - 1][j] * i % p) % p;
            if (j) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % p;
        }
    inv[1] = 1;
    for (int i = 2; i < p; ++ i)
        inv[i] = 1LL * (p - p / i) * inv[p % i] % p;
    for (int i = 0; i < p; ++ i)
        if (a[i]){
            int c = 1;
            for (int j = 0; j < i; ++ j)
                c = 1LL * c * inv[i - j] % p;
            for (int j = i + 1; j < p; ++ j)
                c = 1LL * c * inv[i - j + p] % p;
            if (i){
                coef[0] = 1LL * dp[p - 1][0] * (p - 1) % p * inv[i] % p;
                for (int j = 1; j < p; ++ j)
                    coef[j] = 1LL * (coef[j - 1] + p - dp[p - 1][j]) * inv[i] % p;
                for (int j = 0; j < p; ++ j)
                    coef[j] = 1LL * coef[j] * c % p;
            }
            else
                for (int j = 0; j < p; ++ j)
                    coef[j] = 1LL * dp[p - 1][j + 1] * c % p;
            for (int j = 0; j < p; ++ j)
                ans[j] = (ans[j] + coef[j]) % p;
        }
    for (int i = 0; i < p; ++ i)
        printf("%d ", ans[i]);
}

Measured memory_bytes: 35584
#include <stdio.h>
#include<string.h>
 
int main()
{
    int n,i,T=0,H=0,f;
    char t[101],h[101];
    scanf("%d\n",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s%s",t,h);
        f=strcmp(t,h);
        if(f==0){T+=1;H+=1;}
        else if(f>0)T+=3;
        else H+=3;
    }
    printf("%d %d\n",T,H);
    return 0;
}                                                                                                                                


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

int main(){
	string S;
	ll K;
	cin >> S >> K;
	ll ans = 0;
	string A = "", B="";
	int i = 1;
	A += S[0];
	while (i<S.size() ) {
		if (S[i] != S[0]) break;
		A += S[i];
		i++;
	}
	while (i<S.size() ) {
		B += S[i];
		i++;
	}
	B += A;
	char now = B[0];
	ll cnt = 1;
	for (int i = 1; i < B.size(); i++) {
		if (B[i] == now)	cnt++;
		else {
			ans += (cnt/2)*K;
			cnt = 1;
			now = B[i];
		}
	}
	ans += (cnt/2)*(K-1);
	ll p = cnt - A.size();
	ans += (p/2) + A.size()/2;

	if (B.size() == A.size()) ans = (K*B.size())/2;

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


Measured memory_bytes: 3600
s = str(input())[::-1]

li=['dream'[::-1],'dreamer'[::-1],'erase'[::-1],'eraser'[::-1]]
i = 0
N = len(s)
while i<N:
    d = 0
    for l in li:
        if (s.startswith(l,i)):
            d = len(l)
            break
    if (d>0):
        i += d
        continue
    print("NO")
    break
else:
    print("YES")

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

int a[2][8] = {{2, 10, 3, 9, 4, 8, 6, 12}, {6, 2, 10, 3, 9, 4, 8, 12}};

int main() {
    int n; cin >> n;
    if (n == 3) {
        cout << "2 5 63"; return 0;
    }
    for (int i = 0; i < n; i++) {
        cout << a[n & 1][i & 7] << " ";
        a[n & 1][i & 7] += 12;
    }
    return 0;
}

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

comb_dic = {}


def combination_formula(n, r):
    """nCrは、O(min(n-r, r))で実装する
    Notes:
        分子と分母がかなり大きな値になった場合、計算は遅くなるので注意
        求める値がmodをとった値でいい場合、フェルマーの小定理を使った方法が速い。
    """
    if r > n: return 0

    if n in comb_dic:
        return comb_dic[n]

    r = min(n-r, r)
    bunsi, bunbo = 1, 1
    for i in range(r):
        bunsi = bunsi*(n-i)
        bunbo = bunbo*(i+1)

    comb_dic[n] = bunsi//bunbo
    return comb_dic[n]


def solve():
    N = int(input())
    As = list(map(int, input().split()))

    dic = {}
    for a in As:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1

    # combination_formula(v, 2)はくっそ早いので、
    # しゃくとりっぽく解く
    total = 0
    for key, value in dic.items():
        total += combination_formula(value, 2)

    for a in As:
        ans = total
        ans -= combination_formula(dic[a], 2)
        ans += combination_formula(dic[a]-1, 2)
        print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 26140
<?php

$nm = explode(' ', trim(fgets(STDIN)));
$n = $nm[0];
$m = $nm[1];

for($i=0; $i<$n; $i++){
  $s[$i] = explode(' ', trim(fgets(STDIN)));
}

for($i=0; $i<$m; $i++){
  $c[$i] = explode(' ', trim(fgets(STDIN)));
}

$ans = [];
for($i=0; $i<$n; $i++){
  
  $sx = $s[$i][0];
  $sy = $s[$i][1];
  
  $md = [];
  for($j=0; $j<$m; $j++){
    $cx = $c[$j][0];
    $cy = $c[$j][1];   
    $md[$j] = abs($sx-$cx)+abs($sy-$cy);
  }
  asort($md);
  $md_key = array_keys($md);
  array_push($ans, $md_key[0]+1);
}

for($i=0; $i<$n; $i++){
  if ($i !== 0) echo "\n";
  echo $ans[$i];
}
  
?>

Measured memory_bytes: 4604
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        String s =sc.next();
        int i = 0;
        int j= s.length()-1;
        int count = 0;
        while(i<j){
            if(s.charAt(i)=='W' && s.charAt(j)=='R'){
                count++;
                i++;
                j--;
            }else{
                if(s.charAt(i)=='R' && s.charAt(j)=='W'){
                    i++;j--;
                }else{
 
                    if(s.charAt(i)=='W'){
                        j--;
                    }else{
                        i++;
                    }
 
 
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 41260
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
const int MAXN=100+10;
int n,G[MAXN][MAXN],Use[MAXN],Connect[MAXN];
struct node{
	int x,y;
};
node A[MAXN],B[MAXN];
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char c='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(c!='\0')putchar(c);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline bool found(int x)
{
	for(register int i=1;i<=n;++i)
		if(G[x][i]&&!Use[i])
		{
			Use[i]=1;
			if(Connect[i]==0||found(Connect[i]))
			{
				Connect[i]=x;
				return true;
			}
		}
	return false;
}
int main()
{
	read(n);
	for(register int i=1;i<=n;++i)read(A[i].x),read(A[i].y);
	for(register int i=1;i<=n;++i)read(B[i].x),read(B[i].y);
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<=n;++j)
			if(B[i].x>A[j].x&&B[i].y>A[j].y)G[i][j]=1;
	int ans=0;
	for(register int i=1;i<=n;++i)
	{
		memset(Use,0,sizeof(Use));
		if(found(i))ans++;
	}
	write(ans,'\n');
	return 0;
}

Measured memory_bytes: 256
from collections import deque 

n=int(input())
l=deque()

for loop in range(n):
    command=input()
    
    if command=='deleteFirst':
        l.popleft()
    elif command=='deleteLast':
        l.pop()
    else:
        com,num=command.split()

        if com=='insert':
            l.appendleft(num)
        elif com=='delete':
            try:l.remove(num)
            except:pass
    
print(*l)


Measured memory_bytes: 69732
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
 int A,B;
 cin>>A>>B;
 if(A>8||B>8){cout<<":("<<endl;}
 else{cout<<"Yay!"<<endl;}
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

constexpr long long INF = (long long)1e18;

#define x first
#define y second

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


vector<pair<long double,long double>> in;
	
long double cal(long double X, long double Y){
	long double maximum = 0;
	
	for(int i = 0; i < in.size(); i++){
		maximum = max(maximum, (in[i].x - X) * (in[i].x - X) + (in[i].y - Y) * (in[i].y - Y));
	}
	
	return sqrt(maximum);
}
	
long double ternary_search2(long double X, long double l = -100, long double h = 1100){
	long double y1, y2, minimum = INF;
	
	for(int i = 0; i < 50; i++){
		y1 = (2 * l + h) / 3;
		y2 = (l + 2 * h) / 3;
		
		long double f1 = cal(X, y1);
		long double f2 = cal(X, y2);
		
		minimum = min(minimum, f1);
		minimum = min(minimum, f2);
		
		if(f1 < f2) {
			h = y2;
		} else {
			l = y1;
		}
	}
	
	return minimum;
}

long double ternary_search(long double l = -100, long double h = 1100){
	long double x1, x2, minimum = INF;
	
	for(int i = 0; i < 50; i++){
		x1 = (2 * l + h) / 3;
		x2 = (l + 2 * h) / 3;
		
		long double f1 = ternary_search2(x1);
		long double f2 = ternary_search2(x2);

		minimum = min(minimum, f1);
		minimum = min(minimum, f2);
		
		if(f1 < f2) {
			h = x2;
		} else {
			l = x1;
		}
	}
	
	return minimum;
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	
	cin>>N;
	
	in.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].x>>in[i].y;
	}
	
	cout<<ternary_search()<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
string s[100005];
int a[100005][13];
ll ans,c;
int main(void){
	ll n; cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		for(int j=0;j<10;j++){
			int t=s[i][j];
			a[i][j]=t;
		}
		sort(a[i],a[i]+10);
		for(int j=0;j<10;j++){
			s[i][j]=a[i][j];
		}
	}
	sort(s,s+n);
	string t=s[0];
	c=1;
	for(int i=1;i<n;i++){
		//cout<<s[i]<<endl;
		if(s[i]==t){
			c++;
		}else{
			//cout<<c<<endl;
			ans+=c*(c-1)/2;
			c=1;
			t=s[i];
		}
	}
	//cout<<c<<endl;
	ans+=c*(c-1)/2;
	cout<<ans<<endl;
	
	
}


Measured memory_bytes: 12416
package main

import (
        "bufio"
        "fmt"
        "os"
)

func solution(n int, a []int) int {
        const MOD = 1e9 + 7
        out := 0
        cur := make([]int, n+1)
        cur[0] = a[0]
        for i := 0; i < n; i++ {
                cur[i+1] = a[i] + cur[i]
        }
        for i := 0; i < n; i++ {
                sum := (cur[n] - cur[i+1]) % MOD
          out = (out + a[i] * sum) % MOD
        }
        return out
}

func main() {
        r := bufio.NewReader(os.Stdin)
        var n int
        fmt.Fscan(r, &n)
        a := make([]int, n)
        for i := range a {
                fmt.Fscan(r, &a[i])
        }
        fmt.Println(solution(n, a))
}

Measured memory_bytes: 7540
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105000;

int n;
int a[MAXN];
long long dp[MAXN];
long long sum[MAXN];
long long mx = 0;

int main() {

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  } 

  for (int i = n - 1; i >= 0; i--) {
    sum[i] = sum[i + 1] + a[i];
  }

  for (int i = n - 1; i >= 0; i--) {
    dp[i] = a[i] + dp[i + 1];
    if (i == n - 1) {
      mx = -2 * a[i];
    } else {
      dp[i] = max(dp[i], -a[i] + sum[i + 1] + mx);
      mx = max(mx, dp[i + 1] - sum[i + 1] - 2 * a[i]);
    }
    // cerr << dp[i] << endl;
  }

  cout << dp[0] << endl;

  return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<array>

using namespace std;

int main(){
    int n,ans,count=0;
    array<int,100000>h;

    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>h.at(i);
        if(i == 0) continue;
        if(h.at(i-1) >= h.at(i)){
            count++;
        }else{
            if(ans < count) ans = count;
            count = 0;
        }
    }
    if(ans < count) ans = count;
    cout<<ans<<endl;

}

Measured memory_bytes: 640
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B&lang=jp
#include <iostream>

int main(){
	int x,y;
	std::cin >> x >> y;

	while(x >= 1 && y >= 1){
		int X,Y;
		if (x >= y){
			X = x;
			Y = y;
		} else {
			X = y;
			Y = x;
		}
		x = X % Y;
		y = Y;
	}

	std::cout << x+y << std::endl;

}

Measured memory_bytes: 1160
#include<iostream>
#include<map>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    string s;
    map<string , int> votes;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> s;
        votes[s] += 1;
    }
    int max_votes = 0;
    for(auto m : votes)
    {
        if(m.second > max_votes)
            max_votes = m.second;
    }
    for(auto m : votes)
    {
        if(m.second == max_votes)
            cout << m.first << endl;
    }
    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=30000020;
const ll INF=0x3f3f3f3f3f3f3f3fLL;
int bufpos;
char buf[MAXSIZE];
#define NEG 1
void init(){
	#ifdef LOCAL
		freopen("E.txt","r",stdin);
	#endif
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
ll sum[200002];
ll myabs(ll x){
	return x>0?x:-x;
}
int main(){
	init();
	int n=readint();
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+readint();
	ll ans=INF;
	for(int i=1;i<n;i++)
		ans=min(ans,myabs(sum[n]-sum[i]-sum[i]));
	printf("%lld",ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    int c1 = 0, c2 = 0;
    c1 = n / 500;
    int a = n - c1 * 500;
    c1 *= 1000;
    c2 = a / 5;
    c2 *= 5;
    cout << c1 + c2 << endl;
}

Measured memory_bytes: 256
#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++)
#define mod 1000000007

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}

int main() {
ll N;
cin>>N;
ll m=N-1;
vector<ll>a(m);

rep(i,m){
 cin>>a[i];
}
vector<ll>cnt(N);
rep(j,m){cnt[a[j]]++;}

for(ll i=1;i<N;i++){
    cout<<cnt[i]<<endl;
}
cout<<'0'<<endl;
return 0;
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
vll pwx(32);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve(){
    ll n, c0 = 0, c1 = 0, c2 = 0, c3 = 0;
    cin >> n;
    string s;
    rep(i, 0, n){
        cin >> s;
        if(s == "AC")
            c0++;
        if(s == "WA")
            c1++;
        if(s == "TLE")
            c2++;
        if(s == "RE")
            c3++;

    }

    cout << "AC x " << c0 << nl;
    cout << "WA x " << c1 << nl;
    cout << "TLE x " << c2 << nl;
    cout << "RE x " << c3 << nl;
}

int main(){
    boost;
    // cal(3);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define vi vector<int>
#define umap unordered_map
#define pii pair<int, int>
#define vpii vector<pii>
#define uset unordered_set
#define frw(i, a, b) for(int i = (a); i < (b); i++)
#define bck(i, a, b) for(int i = (a); i > (b); i--)
#define T() int testcases; cin >> testcases; frw(TC, 1, testcases + 1)
#define tez ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define fi first
#define se second
#define pow asdihagsiduh
#define pub push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) (int)(a.size())
#define sq(a) ((a) * (a))

#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1> 
void ZZ(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}

//console o/p without variable names
#define trace1(...) ZZZ(__VA_ARGS__)
template<typename Arg1>
void ZZZ(Arg1&& arg1){
    cerr << arg1 << endl;
}
template<typename Arg1, typename... Args>
void ZZZ(Arg1&& arg1, Args&&... args){
    cerr << arg1 << ' ';
    ZZZ(args...);
}

signed main(){
    tez
    int n, k, s; cin >> n >> k >> s;
    int mx = 1e9;
    if(s == 1){
        frw(i, 0, k)    cout << 1 << ' ';
        frw(i, 0, n - k)    cout << mx << ' ';
    }   else
    if(s == 1e9){
        frw(i, 0, k)    cout << mx << ' ';
        frw(i, 0, n - k)    cout << 1 << ' ';
    }
    else{
        frw(i, 0, k)    cout << s << ' ';
        frw(i, 0, n - k)    cout << mx << ' ';
    }
}

Measured memory_bytes: 1280
n = readline.chomp.to_i
n.times{
  v = readline.chomp.split.map{|c| c.to_i}

# (1..10).to_a.permutation{|v|
  # p v
  stack1 = [0]
  stack2 = [0]

  v.each{|c|
    # if stack1[-1] < c
    #   stack1.push(c)
    # elsif stack2[-1] < c
    #   stack2.push(c)
    # else
    #   puts "NO"
    #   break
    # end
    if stack1[-1] > stack2[-1]
      if stack1[-1] < c
        stack1.push(c)
      elsif stack2[-1] < c
        stack2.push(c)
      else
        puts "NO"
        break
      end
    else
      if stack2[-1] < c
        stack2.push(c)
      elsif stack1[-1] < c
        stack1.push(c)
      else
        puts "NO"
        break
      end
    end
  }
  if stack1.size + stack2.size == 12
    puts "YES"
  end
  # p stack1
  # p stack2
}

Measured memory_bytes: 8664
N = int(input())
S = []
for i in range(N):
    S.append(input())
md = {}
for i in S:
    if i[0] in ["M","A","R","C","H"]:
        md[i[0]] = md.get(i[0],0) + 1
v = 0
for i in ["MAR","MAC","MAH","MRC","MRH","MCH","ARC","ARH","ACH","RCH"]:
    v += md.get(i[0],0) * md.get(i[1],0) * md.get(i[2],0)
print(v)


Measured memory_bytes: 9752
#include<iostream>
#include<vector>

using namespace std;
#define ll long long int

int main(){
	ll h, n; cin >> h >> n;
	vector<int> v(n);
	int temp;
	ll sum = 0;
	for(int i=0; i<n; i++){


		scanf("%d", &temp);
		sum += temp;


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

	// int ans = 0;
	
	return 0;
}

Measured memory_bytes: 640
N, A, B, C = map(int, input().split())
L = [ int(input()) for _ in range(N)]
res = 10 ** 9

import itertools

#n桁のm値のbitを生成
def bit(n, m):
    bit_list = list(itertools.product([i for i in range(m)], repeat=n))
    return bit_list

bit = bit(N, 4)

for b in bit:
    tmp1, tmp2, tmp3, cost = 0, 0, 0, 0
    x, y, z = 0, 0, 0
    for i in range(N):
        if b[i] == 1:
            tmp1 += L[i]
            if x != 0:
                cost += 10
            x += 1
            
        if b[i] == 2:
            tmp2 += L[i]
            if y != 0:
                cost += 10
            y += 1
            
        if b[i] == 3:
            tmp3 += L[i]
            if z != 0:
                cost+= 10
            z += 1
    if x > 0 and y > 0 and z > 0:        
        res = min(abs(A-tmp1)+abs(B-tmp2)+abs(C-tmp3)+cost, res)

print(res)

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

int n;
vector<int> a(10);
vector<int> b{0,0,0,0,0,0,0,0,0,0};
vector<vector<int>>s(101,vector<int>(10)); 
vector<vector<int>>p(101,vector<int>(11));

long ans =-10000000000;

void calc(void){
  long sum=0;
  for(int i=0;i<n;i++){
    int kazu=0;
    for(int j=0;j<10;j++){
      if(s.at(i).at(j)==1&&a.at(j)==1){
      kazu++;
      }
    }
    sum +=p.at(i).at(kazu);
  }
  ans =max(sum,ans);
}
    
  
  

void dfs(int pos){
  if(pos ==10){
    if(a==b){
      return;
    }
    calc();
    return;
  }
  a.at(pos)=0;dfs(pos+1);
  a.at(pos)=1;dfs(pos+1);
}
    

int main() {
  cin >>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> s.at(i).at(j);
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<11;j++){
      cin >> p.at(i).at(j);
    }
  }
  dfs(0);
  cout <<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
 
int main(){
  int n, x[100], y[100];
  int i, k, max = 0;
  double ans;
 
  scanf("%d", &n);
   
  for(i = 0; i<n; ++i){
    scanf("%d", &x[i]);
  }
  for(i = 0; i<n; ++i){
    scanf("%d", &y[i]);
  }
 
  for(i = 1; i<4; ++i){
    ans = 0;
    for(k = 0; k<n; ++k){
      ans += pow(fabs(x[k] - y[k]), i);
      if(max < fabs(x[k] - y[k])){
    max = fabs(x[k] - y[k]);
      }
    }
    ans = pow(ans, 1.0/i);
 
    printf("%lf\n", ans);
  }
 
  printf("%d\n", max);
   
  return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);

int main() {
    int N;
    cin >> N;
    int nowT = 0, nowX = 0, nowY = 0;
    string ans = "Yes";
    rep(i, N){
        int t, x, y;
        cin >> t >> x >> y;
        int dT = t - nowT;
        int dx = abs(x - nowX);
        int dy = abs(y - nowY);
        if (dT < dx + dy) ans = "No";
        int dist = dx + dy;
        if (dist % 2 == 0){
            if (dT % 2 == 1) ans = "No";
        } else {
            if (dT % 2 == 0) ans = "No";
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int N;
  int answer = 0;
  cin >> N;
  vector<int> value(N);
  vector<int> cost(N);
  for (int i = 0; i < N; i++) {
    cin >> value.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> cost.at(i);
  }
  for(int i = 0; i < N; ++i){
    if(value.at(i) - cost.at(i) > 0){
      answer += value.at(i) - cost.at(i);
    }else{
      //nothing.do
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
<?php

$home = explode(" ", trim(fgets(STDIN)));

$distance = explode(" ", trim(fgets(STDIN)));

$max = ($home[0] - $distance[$home[1]-1]) + $distance[0];
$check = 0;
for($i=1; $i<$home[1]; $i++){
	if($distance[$i]-$distance[$i-1] > $max){
		$max = $distance[$i]-$distance[$i-1];
		$check = $i;
	}
}

$ans = 0;
if($check == 0){
	for($i=1; $i<$home[1]; $i++){
		$ans += $distance[$i]-$distance[$i-1];
	}
}else{
	for($i=$check; $i<$home[1]-1; $i++){
		$ans += $distance[$i+1]-$distance[$i];
	}
	$ans += ($home[0] - $distance[$home[1]-1]) + $distance[0];
	for($i=0; $i<$check-1; $i++){
		$ans += $distance[$i+1]-$distance[$i];
	}
}
echo $ans;

Measured memory_bytes: 39980
#include <iostream>
using namespace std;
int main()
{
    int k,s;
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=k;i++)
        for(int j=0;j<=k;j++)
        {
            int ij=s-i-j;
            if(ij<=k && ij >=0)ans++;
        }
    cout<<ans<<endl;
}

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

int main(){
    int N, d, sum=0;
    vector<int> v;

    cin >> N;
    for (int i=0; i<N; i++) {
        cin >> d;
        v.push_back(d);
    }

    for (int i=0; i<N; i++) {
        for (int j=i+1; j<N; j++) {
            sum += v[i] * v[j];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace abc057_c
{
    class Program
    {
        static bool IsPrime(long n)
        {
            if (n <= 2)
                return true;
            if (n % 2 == 0)
                return false;
            for (long i = 3; i <= n / i; i += 2)
                if (n % i == 0)
                    return false;
            return true;
        }
        static void solve(long n)
        {
            long min = 99999;
            for(long i = 3; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    min = (n / i).ToString().Length;
                }
            }
            Console.WriteLine(min);
        }
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            if (IsPrime(N))
            {
                Console.WriteLine(N.ToString().Length);
            }
            else
            {
                solve(N);
            }
        }
    }
}


Measured memory_bytes: 13140
use proconio::input;
use proconio::marker::Usize1;
use std::collections::HashSet;

struct UnionFind {
    parent: Vec<usize>,
    rank: Vec<i32>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind {
            parent: (0..n).map(|i| i).collect(),
            rank: vec![0; n],
        }
    }

    fn find(&mut self, n: usize) -> usize {
        if self.parent[n] == n {
            return n;
        };
        self.parent[n] = self.find(self.parent[n]);
        self.parent[n]
    }

    fn same(&mut self, n: usize, m: usize) -> bool {
        self.find(n) == self.find(m)
    }

    fn unit(&mut self, n: usize, m: usize) {
        let n = self.find(n);
        let m = self.find(m);
        if n == m {
            return;
        }
        if self.rank[n] > self.rank[m] {
            self.parent[m] = n;
        } else {
            self.parent[n] = m;
            if self.rank[n] == self.rank[m] {
                self.rank[n] += self.rank[m];
            }
        }
    }
}

fn main()
{
    input! {
    n:usize,
    m:usize,
    v:[(Usize1,Usize1,i32);m],
    }

    let mut uf = UnionFind::new(n);
    for &(a, b, _) in v.iter() {
        uf.unit(a, b);
    }

    let mut id: HashSet<usize> = (0..n).into_iter().map(|i| uf.find(i)).collect();
    println!("{}", id.iter().count());
}

Measured memory_bytes: 8208
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <algorithm>

using namespace std;

#define INF (1<<30)

typedef pair<int,int> _P;
typedef pair<_P,int> P;

int map[100][100];
bool vst[100][100];
int dx1[6]={-1,0,1,0,-1,-1},dy1[6]={-1,-1,0,1,1,0};
int dx2[6]={0,1,1,1,0,-1},dy2[6]={-1,-1,0,1,1,0};

int main() {
	int m,n,s,t;
	while(scanf("%d",&m),m) {
		scanf("%d",&n);
		scanf("%d",&s);
		for(int j=0;j<n;j++) {
			for(int i=0;i<m;i++) {
				map[i][j]=INF;
			}
		}
		for(int i=0;i<s;i++) {
			int x,y;
			scanf("%d %d",&x,&y);x--;y--;
			memset(vst,false,sizeof(vst));
			map[x][y]=0;
			vst[x][y]=true;
			queue<P> que;
			que.push(P(_P(x,y),0));
			while(!que.empty()) {
				P p=que.front();que.pop();
				int *dx,*dy;
				if((p.first.second+1)%2) dx=dx1,dy=dy1;
				else dx=dx2,dy=dy2;
				for(int i=0;i<6;i++) {
					int nx=p.first.first+dx[i],ny=p.first.second+dy[i];
					if(0<=nx&&nx<m&&0<=ny&&ny<n&&!vst[nx][ny]) {
						vst[nx][ny]=true;
						map[nx][ny]=min(p.second+1,map[nx][ny]);
						que.push(P(_P(nx,ny),p.second+1));
					}
				}
			}
		}
		scanf("%d",&t);
		int ans=0;
		for(int i=0;i<t;i++) {
			int x,y;
			scanf("%d %d",&x,&y);x--;y--;
			memset(vst,false,sizeof(vst));
			vst[x][y]=true;
			queue<P> que;
			que.push(P(_P(x,y),0));
			int count=0;
			while(!que.empty()) {
				P p=que.front();que.pop();
				int *dx,*dy;
				if(p.second<map[p.first.first][p.first.second]) count++;
				if((p.first.second+1)%2) dx=dx1,dy=dy1;
				else dx=dx2,dy=dy2;
				for(int i=0;i<6;i++) {
					int nx=p.first.first+dx[i],ny=p.first.second+dy[i];
					if(0<=nx&&nx<m&&0<=ny&&ny<n&&!vst[nx][ny]) {
						vst[nx][ny]=true;
						que.push(P(_P(nx,ny),p.second+1));
					}
				}
			}
			if(ans<count) ans=count;
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define elif else if
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
	init();

	int n, k; cin >> n >> k;
	VI l(n), r(n);
	FOR(i, 0, k)cin >> l[i] >> r[i];
	VL dp1(n), dp2(n);
	dp1[0] = 1;
	FOR(i, 0, n) {
		if (0 < i)(dp2[i] += dp2[i - 1]) %= MOD;
		(dp1[i] += dp2[i]) %= MOD;
		FOR(j, 0, k) {
			if (i + l[j] < n)(dp2[i + l[j]] += dp1[i]) %= MOD;
			if (i + r[j] + 1 < n)(dp2[i + r[j] + 1] += MOD - dp1[i]) %= MOD;
		}
	}
	print(dp1[n - 1]);

	return 0;
}


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

int main(){
	int A,B;
  	string S;
  	
  	cin >> A >> B >> S;
  
  	if(S[A] != '-'){
    	cout <<"No" <<endl;
      	return 0;
    
    }
  	
  	for(int i = 0; i <= A+B; i++){
    	if(i == A)continue;
      	if(S[i]<'0' || '9'<S[i]){
        	cout <<"No"<<endl;
          	return 0;
        
        }
    
    
    }
  	cout <<"Yes"<<endl;
  	return 0;



}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b;
    cin>>a>>b;
    a*=b;
    if(a&1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main(void){
    char a[10],b[10],c[10];
    cin >> a >> b >> c;
    if(a[strlen(a)-1] == b[0] && b[strlen(b)-1] == c[0])cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import random
class Dice:
    def __init__(self, usr_input):
        self.eyes = list(map(int, usr_input.split()))
        self.pos = {label:eye for label, eye in zip(range(1, 7), self.eyes)}
        #self.com = list(command)

    def roll(self,c):
        self.eyes = [n for n in self.pos.values()]
        if c == 'E':
            self.pos[1] = self.eyes[3]
            self.pos[3] = self.eyes[0]
            self.pos[4] = self.eyes[5]
            self.pos[6] = self.eyes[2]
        elif c == 'N':
            self.pos[1] = self.eyes[1]
            self.pos[2] = self.eyes[5]
            self.pos[5] = self.eyes[0]
            self.pos[6] = self.eyes[4]
        elif c == 'S':
            self.pos[1] = self.eyes[4]
            self.pos[2] = self.eyes[0]
            self.pos[5] = self.eyes[5]
            self.pos[6] = self.eyes[1]
        elif c == 'W':
            self.pos[1] = self.eyes[2]
            self.pos[3] = self.eyes[5]
            self.pos[4] = self.eyes[0]
            self.pos[6] = self.eyes[3]

    def right_print(self, top, front):
        while self.pos[1] != top or self.pos[2] != front:
            c = random.choice(['N', 'E', 'W', 'S'])
            self.roll(c)

        print(self.pos.get(3))

if __name__ == '__main__':
    dice1 = Dice(input())
    #dice1.roll()
    num = int(input())
    for i in range(num):
        question = list(map(int, input().split()))
        dice1.right_print(question[0], question[1])

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

int main() {
	int n;
	cin >> n;
	vector<int> vec(n);

	for (auto& e : vec) {
		cin >> e;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += vec.at(i);
		int d = vec.at(i);
		for (int j = i + 1; j < n; j++) {
			if (vec.at(j) - d >= 0) {
				vec.at(j) = vec.at(j) - d;
			}
			else {
				d = vec.at(j);
				vec.at(j) = 0;
			}
		}
	}
	cout << ans << endl;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> ps(n);
    for (int& p : ps) {
        cin >> p;
        --p;
    }
    int cycles = 0;
    vector<int> visited(n, false);
    function<void (int)> dfs = [&](int i) {
        visited[i] = true;
        if (!visited[ps[i]]) {
            dfs(ps[i]);
        }
    };
    for (int i = 0; i < n; ++i) {
        if (!visited[i]) {
            ++cycles;
            dfs(i);
        }
    }
    if (cycles >= n-1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

const int MAX_V = 2e5;
vector<int> es[MAX_V];
int st, en; //端点
vector<int> d(MAX_V, 0);

void dfs(int now, int pre){
    if(pre == -1) d[now] = 0;
    else d[now] = d[pre]+1;
    for(auto &e: es[now]){
        if(e == pre) continue;
        dfs(e, now);
    }
}

int tree_diameter(){
    dfs(0, -1);
    int ret = -1;
    rep(i, MAX_V){
        if(chmax(ret, d[i])) st = i;
    }
    dfs(st, -1);
    ret = -1;
    rep(i, MAX_V){
        if(chmax(ret, d[i])) en = i;
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    rep(i, N-1){
        int u, v; cin >> u >> v; u--, v--;
        es[u].pb(v), es[v].pb(u);
    }
    int r = tree_diameter();
    if(r%3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;
}

Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    if(S == "SUN")
    {
        cout << "7";
    }
    else if(S == "MON")
    {
        cout << "6";
    }
    else if(S == "TUE")
    {
        cout << "5";
    }
    else if(S == "WED")
    {
        cout << "4";
    }
    else if(S == "THU")
    {
        cout << "3";
    }
    if(S == "FRI")
    {
        cout << "2";
    }
    else if(S == "SAT")
    {
        cout << "1";
    }
    cout << endl;
}




Measured memory_bytes: 3568
#include <stdio.h>

int compare(int A, int B) {
    if ((A + B) > 2 * A - 1) {
        if ((A + B) > 2 * B - 1) {
            return A + B;
        } else {
            return 2 * B - 1;
        }
    } else {
        if (2 * A - 1 > 2 * B - 1) {
            return 2 * A - 1;
        } else {
            return 2 * B - 1;
        }
    }
}

int main(int argc, char const *argv[]) {
    int A, B;
    scanf("%d", &A);
    scanf("%d", &B);

    int r = compare(A,B);

    printf("%d",r);
    
    return 0;
}


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

bool judge(string S){
    int length=S.length();
    vector<char>Schar;
    vector<char>ScharReverse;
    for(int i=0;i<length;i++){
        Schar.push_back(S[i]);
    }
    for(int i=length-1;i>=0;i--){
        ScharReverse.push_back(Schar[i]);
    }
    if(Schar==ScharReverse){
        return true;
    }else{
        return false;
    }

}

int main()
{
    string S;
    cin>>S;
    int N=S.length();
    if(judge(S)&&judge(S.substr(0,(N-1)/2))&&judge(S.substr(((N+3)/2)-1))){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    } 
    return 0;
}

Measured memory_bytes: 256
def main():
    N,X,M = map(int,input().split())
    dict = {key:0 for key in range(M)}
    #print(dict)
    if N==1:
        return X
    dict[X] += 1
    cnt = 1
    A = [0]*(M+1)
    A[1] = X
    ans = X
    tmp = X
    for i in range(1,N,1):
        tmp = (tmp**2)%M
        if dict[tmp] != 0:
            break
        ans += tmp
        A[i+1] = A[i]+tmp
        cnt += 1
        dict[tmp] += cnt

    num = N - cnt#残り足す回数
    roop_num = cnt - dict[tmp] + 1
    syo = num//roop_num
    amari = num%roop_num
    ans += syo*(A[cnt]-A[dict[tmp]-1])
    ans += (A[dict[tmp]+amari-1]-A[dict[tmp]-1])
    return ans

print(main())


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

int main(){
  int i,j,cnt=0;
  int a,b,c;
  cin>>a>>b>>c;
  if((a>c && c>b) || (a<c && c<b))cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
bool is_prime(int x)
{
	if(x<=2)return false;
	For(i,2,sqrt(x))if(x%i==0)return false;
	return true;
}
int main()
{
	int n,cnt=0,i=0;
	cin>>n;
	while(cnt<n)
	{
		int p=11+10*i;
		if(is_prime(p))
		{
			cnt++;
			cout<<p<<" ";
		}
		i++;
	}
	return 0;
}



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

int main()
{
  int h,w;
  cin >> h >> w;
  
  char s[h][w];
  rep(i,h){
    rep(j,w){
      cin >> s[i][j];
    }
  }
  
  
  char ans[h][w];
  int flag = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '#'){
        for(int k = 0; k < w; k++){
          ans[i][k] = s[i][k];
        }
        flag = 1;
        break;
      }
    }//for
    if(flag == 0){
      for(int k = 0; k < w; k++){
         ans[i][k] = '?';
      }
    }//if
    flag = 0;
  }//for
  
  flag = 0;
  for(int i = 0; i < w; i++){
    for(int j = 0; j < h; j++){
      if(s[j][i] == '#'){
        for(int k = 0; k < h; k++){
          if(ans[k][i] != '?')
            ans[k][i] = s[k][i];
        }
        flag = 1;
        break;
      }
    }//for
    if(flag == 0){
      for(int k = 0; k < h; k++){
        ans[k][i] = '?';
      }
    }//if
    flag = 0;
  }//for
  
  flag = 0;
  rep(i,h){
    rep(j,w){
      if(ans[i][j] != '?'){
        cout << ans[i][j];
        flag = 1;
      }
    }
    if(flag == 1){
      cout << endl;
    }
    flag = 0;
  }
 
}

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

using namespace std;

#define debug(x) cout << #x << " : " << x << '\n';

// code //
const int MOD = 1e9 + 7;

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

	vector<int> dp(s+1);
	dp[0]=1;
	for(int i=1; i<=s; ++i) {
		for(int j=3; j<=i; ++j)
			dp[i]=(dp[i]+dp[i-j])%MOD;
	}

	cout << dp[s];
}	


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

int main(){
	int n; cin >> n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	ll ans=0;
	sort(a.rbegin(),a.rend());
	for(int i=0;i<n;i++){
		(ans+=mod_pow(4,n-1)*a[i]%mod*(i+2))%=mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792