akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
using namespace std;
using ll = long long;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
int main(){
  ll N;
  cin>>N;
  ll g;
  cin>>g;
  for(int i=0;i<N-1;++i){
    ll A;
    cin>>A;
    g=gcd(A,g);
  }
  cout<<g<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[]) {
	int n, x, y;
	cin >> n >> x >> y;
	unordered_map<int, unordered_set<int>> um;
	for (int i = 1; i < n; i++) {
		um[i].insert(i + 1);
		um[i + 1].insert(i);
	}
	um[x].insert(y);
	um[y].insert(x);
	unordered_map<int, int> res;
	vector<vector<int>> dist(n + 1, vector<int>(n + 1, 0x3f3f3f3f));
	for (int i = 1; i < n; i++) {
		vector<int> v(n + 1, 0);
		vector<int> v1, v2;
		v1.push_back(i);
		int d = 0;
		while (v1.size() > 0) {
			v2.clear();
			for (auto node : v1) {
				dist[i][node] = d;
				if (i < node) res[d]++;
				for (auto next : um[node]) {
					if (v[next] == 1) continue;
					v[next] = 1;
					v2.push_back(next);
				}
			}
			d++;
			v1 = v2;
		}
	}
	for (int i = 1; i < n; i++)
		cout << res[i] << endl;
}









Measured memory_bytes: 16512
#include <iostream>
#include <climits>

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

  int H, W;
  std::cin >> H;
  std::cin >> W;

  uint8_t G[50][50];
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char ch;
      std::cin >> ch;
      G[i][j] = (ch == '#'? 1: 2);
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (G[i][j] == 1) {
        bool u = false;
        bool d = false;
        bool l = false;
        bool r = false;
        if (i - 1 >= 0 && G[i - 1][j] == 1) {
          u = true;
        }
        if (i + 1 < H && G[i + 1][j] == 1) {
          d = true;
        }
        if (j - 1 >= 0 && G[i][j - 1] == 1) {
          l = true;
        }
        if (j + 1 >= 0 && G[i][j + 1] == 1) {
          r = true;
        }

        if (!u && !d && !l && !r) {
          std::cout << "No" << std::endl;
          return 0;
        }
      }
    }
  }

  std::cout << "Yes" << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		for (int i = A; i <= B; i++) {
			if (i % K == 0) {
				System.out.println("OK");
				System.exit(0);
			}
		}
		System.out.println("NG");
	}
}

Measured memory_bytes: 35652
use proconio::input;
use proconio::marker::*;
use std::collections::HashMap;

fn main() {
  input! {
    n: usize,
    chars: String
  }
  
  let mut left = vec![0;26];
  let mut right = vec![0;26];
  for v in chars.as_bytes().iter() {
    let i = (v - 97u8) as usize;
    right[i] += 1;
  }
  
  let mut max = 0;
  for v in chars.as_bytes().iter() {
    let i = (v - 97u8) as usize;
    right[i] -= 1;
    left[i] += 1;
    
    let mut temp = 0;
    for ii in 0..26 {
      if 0 < right[ii] && 0 < left[ii] {
        temp += 1;
      }
    }
    max = std::cmp::max(max, temp);
  }
   
  println!("{}", max);
}

Measured memory_bytes: 2132
//
//  main.cpp
//  11
//
//  Created by Charles Wayne on 2018/3/4.
//  Copyright © 2018年 Charles Wayne. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;
int n;
int main(int argc, const char * argv[]) {
    while(~scanf("%d",&n)){
        cout<<n/3<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

n, m = map(int, input().split())

# 区間の終端でソート
ab = sorted([tuple(map(int, input().split())) for i in range(m)], key=itemgetter(1))
# 前回除いた橋
removed = -1
ans = 0

for a, b in ab:
    # a が removed より大きい = まだ取り除いてない
    if a > removed:
        removed = b - 1
        ans += 1

print(ans)


Measured memory_bytes: 18972
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
typedef long long ll;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1000000007;

ll dp[100010];

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }
    dp[0] = 1LL;
    vector<ll> num(N, 0LL);
    num[0] = 3LL; // num[i]:=i回出たやつ
    for(int i = 0; i < N; i++) {
        dp[i + 1] = (dp[i] * num[A[i]]) % MOD;
        num[A[i]]--;
        num[A[i] + 1]++;
        // rep(i, 5) cout << num[i] << " ";
        // cout << endl;
    }
    cout << dp[N] << endl;
    return 0;
}

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

int main(){
	int n, i;
	cin >> n >> i;
	cout << n-i+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
string s; cin >> s;
int n = s.size();
for(int i = 0; i < n; ++i){
char c = s[i];
if(c=='1')cout << '9';
else if(c == '9')cout << '1';
else cout << c;
}
cout << endl;
}


Measured memory_bytes: 256
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def comb(n, r, p):
    ret = 1
    while 1:
        if (r == 0):
            break
        N = n % p
        R = r % p
        if N < R:
            return 0
        for i in range(R):
            ret = ret * (N-i) % p
        imul = 1
        for i in range(R):
            imul = imul * (i+1) % p
        ret = ret * modinv(imul, p) % p
        n //= p
        r //= p
    return ret

mod = 10 ** 9 + 7
N, A, B = map(int, input().split())
tmp = (2 ** N - 1) % mod 
a = comb(N, A, mod)
b = comb(N, B, mod)
print(((tmp + mod) - a - b ) % mod)

Measured memory_bytes: 280860
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
    char str[105];
    int i,t,len;
    while(scanf("%s",str)!=EOF)
    {
        t=1;
        len=strlen(str);
        for(i=0;i<len;i+=2)
            if(str[i]=='L') {t=0;break;}
        if(t==0) {printf("No\n");continue;}
        for(i=1;i<len;i+=2)
            if(str[i]=='R') {t=0;break;}
        if(t==0) {printf("No\n");continue;}
        printf("Yes\n");
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
using namespace std;
int main(){
    int N,M,sum=0,x,max=0,mai,ans=0,san;
    cin >> N >> M;
    
    
    vector<int> vec(M);
    priority_queue <int> que;
    vector<int> sa(M);
    REP(i,M){
        cin >> x;
        sum += x;
        vec[i] = x;
    }
  if(N>=M){
    cout << 0 <<endl;
  }else if(M == 1){
        cout << 0 <<endl;
        return 0;
    }else{
    SORT(vec);

    REP(i,M-1){
        san = abs(vec[i+1]-vec[i]);
        que.push(san);
        ans += san;
    }

    REP(i,N-1){
        x = que.top();
        que.pop();
        ans -= x;
    }
    cout << ans << endl;
    }

}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 1100000;
char S[N], T[N];
set <int> C[30];
int vis[N], ans;
queue <int> Q;
int main()
{
    scanf("%d", &n);
    scanf("%s%s", S, T);
    for (int i = 0; i < n; ++ i)
        C[S[i] - 'a'].insert(i);
    int sam = 1;
    for (int i = 0; i < n; ++ i)
        if (S[i] != T[i]) sam = 0;
    if (sam) {puts("0"); return 0;}
    int cnt = 0;
    for (int i = n - 1, j = n, l = n; ~i; -- i)
        if (i == 0 || T[i - 1] != T[i])
        {
            set <int> :: iterator it = C[T[i] - 'a'].upper_bound(min(l - 1, i));
            cnt ++;
            if (it == C[T[i] - 'a'].begin())
            {
                puts("-1");
                return 0;
            }
            it --;
            int w = *it;
            while (!Q.empty())
            {
                int x = Q.front();
                if (x - (cnt - vis[x] - 1) > i) Q.pop();
                else break;
            }
            if (!Q.empty())
            {
                int x = Q.front();
                ans = max(ans, (cnt - vis[x]) + 2);
            }
            else ans = max(ans, i == w? 1: 2);
            if (w != i) {Q.push(w); vis[w] = cnt;}
            l = w;
        }
    printf("%d", ans);
}


Measured memory_bytes: 57600
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const long long mod=1e9+7;
long long n,m;
long long dp[100000+10];
long long sum;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int a;
        cin>>a;
        dp[a]=-inf;
    }
    dp[0]=-inf;
    for(int i=0;i<=n;i++)
    {
        if(dp[i]==-inf)
        {
            if(dp[i+1]==-inf)
            {
                if(i!=0)
                {
                    cout<<"0";
                    return 0;
                }
                else
                {
                    if(dp[2]==-inf)
                    {
                        cout<<"0";
                        return 0;
                    }
                    else
                    {
                        dp[2]=1;
                        dp[1]=0;
                        continue;
                    }
                }
            }
            else
            {
                if(i!=0)
                {
                    dp[i+1]=dp[i-1];
                    dp[i]=0;
                    continue;
                }
                else
                {
                    dp[1]=1;
                    dp[0]=1;
                    continue;
                }
            }
        }
        if(dp[i]==1||i==1)  continue;
        dp[i]=dp[i-2]+dp[i-1];
        dp[i]%=mod;
    }
    sum=dp[n];
    cout<<sum%mod;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    static long N;
    static long C;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        long res = 0;
        func(0, 0);
        System.out.println(C);
    }

    static void func(long cur, int use) {
        if(cur > N) return;
        if(use == 0b111) {
            C++;
        }

        // 7 を付け加える
        func(cur * 10 + 7, use | 0b001);

        // 5 を付け加える
        func(cur * 10 + 5, use | 0b010);

        // 3 を付け加える
        func(cur * 10 + 3, use | 0b100);
    }
}


Measured memory_bytes: 35500
words = {"dream": "A", "dreamer": "A", "erase": "A", "eraser": "A"}
 
ans = []
 
inputs = str(input())
 
inputs = inputs.replace("eraser", "").replace("erase", "")
inputs = inputs.replace("dreamer", "").replace("dream", "")

if len(list(inputs)) > 0:
  print("NO")
else:
  print("YES")

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

int main()
{int n, A, ans=0;
while(cin >> n, n){ans=0; A = 1000 - n;
int C[6]={500, 100, 50, 10, 5, 1};
rep(i, 6)
{ans += A/C[i]; A %= C[i];}
cout << ans << endl;}

       
 }


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

using namespace std ;

int main ()
{
    string s ;
    bool A_exists = 0 , B_exists = 0 ; // we declare two boolean variables to check weather the letters "A" and "B" exist

    cin >> s ;

    for ( int i = 0 ; i < s.size() ; i++ )
    {
        if ( s[i] == 'A' )          A_exists = true ; // once we find the letter "A" we assign the variable A_exists with value true
        else if ( s[i] == 'B' )     B_exists = true ; // same for letter B
    }

    if ( A_exists && B_exists )     cout << "Yes" ; // if letter "A" and letter "B" exist the answer is Yes
    else                            cout << "No" ; // otherwise answer is No

}


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

typedef long long ll;

#define F for(ll i = 1; i < N; i++)

int main() {

    ll N;
    cin >> N;
    ll count = 0;

    F{
        for(ll j = 1; j < N; j++){
            if(i * j < N){
                count++;
            }else{
                break;
            }
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define LL long long


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

 int x[3];
 int y[3];
 x[0] = 0;
 for (int i = 0; i < 3; i++) y[i] = a[0][i] - x[0];
 for (int i = 0; i < 3; i++) x[i] = a[i][0] - y[0];
 
 bool check = true;
 
 for (int i = 0; i < 3; i++){
     for (int j = 0; j < 3; j++){
         if (x[i] + y[j] != a[i][j]){
             check = false;
         }
     }
 }

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

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

public class Test
{
	public static void Main()
	{
        string[] line = Console.ReadLine().Split(' ');
        int n = int.Parse(line[0]);
        int k = int.Parse(line[1]);

        long ans = k;

        for(int i = 1; i < n ; i++) ans *= k - 1;
        Console.WriteLine(ans);
    }                                                                                                                                                                       
}

Measured memory_bytes: 13140
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int a, b; cin >> a >> b;
    long double c = sqrt(a * pow(10, int(log10(b))+1)+b);
    cout <<(c == int(c) ? "Yes" : "No") << endl;
}

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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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

long long stoi(string str) {
	long long ret;
	stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

void solve() {
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll nopair = a*x + b*y;
	ll partpair = min(x, y) * 2 * c;
	ll onlypair = max(x, y) * 2 * c;
	if (x != y) {
		if (x < y) {
			partpair += (y - x)*b;
		}
		else {
			partpair += (x - y)*a;
		}
	}
	P(min(min(nopair, partpair),onlypair));
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define x first
#define y second
typedef long long LL;
typedef pair<int, int> PII;
void R(char &c){c = getchar();};void R(string &s){scanf("%s",s.c_str());}void R(char s[]){scanf("%s",s);}template<typename T>void R(T&x){int f=1;x=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch-48);ch=getchar();}x*=f;}template<typename T,typename...Args>void R(T&x,Args&...args){R(x),R(args...);}void _W(const string&s){printf("%s",s.c_str());}void _W(const char&c){putchar(c);};void _W(const char s[]){printf("%s",s);}template<typename T>void _W(T x){if(x<0){putchar('-');x=-x;}static int dig[130];int top=0;do{dig[top++]=x%10,x/=10;}while(x);while(top)putchar(dig[--top]+48);}template<typename T>void _W(const vector<T> a){for(int i=0;i<SZ(a);++i)_W(a[i]),putchar(' ');}void W(){}template<typename T,typename...Args>void W(const T&x,const Args&...args){_W(x);putchar(sizeof...(args)?' ':'\n');W(args...);}


void solve(){
	int a, b, c; R(a, b, c); W(c, a, b);
}

signed main(){
	//int T; R(T); while(T -- )
	solve(); return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
using ll = long long;
//#define int ll
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
signed main(){
    int x,y,z; cin>>x>>y>>z;
    for(int i=0; ;i++){
        if(i*y+(i+1)*z>x){
            cout<<i-1<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		StringBuilder sb = new StringBuilder();
		
		for(int i = 0; i < str.length(); i++) {
			char check = str.charAt(i);
			// アルファベットかどうか
			if(!Character.isLetter(check)) {
				sb.append(check);
			}else if(Character.isUpperCase(check)) {
				check = Character.toLowerCase(check);
				sb.append(check);
			}else if(Character.isLowerCase(check)) {
				check = Character.toUpperCase(check);
				sb.append(check);
			}
		}
		
		System.out.println(sb);
	}

}



Measured memory_bytes: 26120
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
using namespace std;
int main() {
	string s; cin >> s;
	if (s == "Sunny") cout << "Cloudy" << endl;
	else if (s == "Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<pii>> g(n); v1i f(n, 0);
  rep(i, n-1){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c); --a; --b;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  deque<int> d;
  d.push_back(0);
  int tmp = 0;
  v1b e(n, 1); e[0] = 0;
  while(!d.empty()){
    d.pop_front();
    for(auto h: g[tmp]){
      if(e[h.fi]){
        e[h.fi] = 0;
        d.push_back(h.fi);
        f[h.fi] = f[tmp] + h.se;
      }
    }
    tmp = d.front();
  }
  rep(i, n){
    if(f[i] & 1) printf("1\n");
    else printf("0\n");
  }
  return 0;
}

Measured memory_bytes: 6784
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	string s; cin >> s;
	int ans = 0, cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'T' || s[i] == 'C' || s[i] == 'A' || s[i] == 'G')cnt++; else cnt = 0;
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100000000

struct NODE {
    int distance;
    int state;
} vertex[101];

int W[101][101];
int n, m;

int min(int a, int b) {
    return (a > b ? b : a);
}

int prim(int start) {
    int x, p, step, sum = 0;

    for (x = 0; x < n; x++) {
	vertex[x].distance = MAX; vertex[x].state = 0;
    }
    vertex[start].distance = 0; 
    for (step = 1; step <= n; step++) {
	int minimum = MAX;
	for (x = 0; x < n; x++)
	    if (vertex[x].state == 0 && vertex[x].distance < minimum) {
		p = x; minimum = vertex[x].distance;
	    }
	vertex[p].state = 1;
	sum += minimum;
	for (x = 0 ; x < n; x++)
	    if (vertex[x].state == 0)
		vertex[x].distance = min(vertex[x].distance, W[p][x]);
    }
    return sum;
}

int main(void) {
    int i, j;
    int from, to, cost;
     
    while (1) {
	scanf("%d", &n);
	scanf("%d", &m);
        if (n == 0) break;
         
        for (i = 0; i < n; i++)
            for (j = 0; j < n; j++)
                W[i][j] = MAX;
         
	for (i = 0; i < m; i++) {
            scanf("%d %d %d", &from, &to, &cost);
            W[from][to] = cost;
	    W[to][from] = cost;
        }

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

Measured memory_bytes: 640
N=int(input())
A=list(map(int,input().split()))
dic={}
ans=0
for i in range(0,N):
    x=i-A[i]
    y=i+A[i]
    if x in dic:
        ans+=dic[x]
    if y not in dic:
        dic[y]=0
    dic[y]+=1
print(ans)


Measured memory_bytes: 111392
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int stage[1024]={0};
        for(int i = 1;i <= n; i++)stage[i] = i;
        int x = 0;
        int cnt = 0;
        for(int i = 1;i < n; i++){
            for(int j = i;j < n; j++){
                x += stage[j];
                if(x == n){
                    cnt++;
                    break;
                }
            }
            x = 0;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

ll a[100000];
ll b[100000];

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

    ll sum = 0;
    for (int i = n - 1; i >= 0; --i)
    {
        a[i] += sum;
        ll x = (b[i] - a[i] % b[i]) % b[i];
        sum += x;
    }
    cout << sum;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
const int MOD = 1e9 + 9;
const int N = 5e5 + 4;
const int p = 31;
const int m = 1e9 + 9;
int preH[N];
string s;
int n;
void compute_hash(string const& s) {
   long long hash_value = 0;
   long long p_pow = 1;
   int indx = 0;
   for (char c : s) {
      hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
      p_pow = (p_pow * p) % m;
      preH[indx++] = hash_value;
   }
}

int power(int b, int p) {
   if (p == 0) return 1;
   int res = power(b, p / 2);
   res = 1LL * res * res % MOD;
   if (p & 1) {
      res = 1LL * b * res % MOD;
   }
   return res;
}

int modInv(int x) {
   return power(x, MOD - 2);
}

int mul(int a , int b , int m){
   return (1LL * (a % m) * (b % m)) % m;
}

int add(int a , int b , int m){
   return (1LL * (a % m) + (b % m)) % m;
}

long long get_hash(int l , int r){
   long long ret = (preH[r] - (l ? preH[l - 1] : 0) + MOD) % MOD;
   return mul(ret , modInv(power(p , l)) , MOD);
}

bool valid(int sz){
   unordered_map<int , bool> mp;
   for(int i = n - sz; i >= 0 ; --i){
      int cur = get_hash(i , i + sz - 1);
      mp[cur] = true;
      int j = i - sz;
      if(j < 0)return false;
      int nxt = get_hash(j , j + sz - 1);
      if(mp.count(nxt)){
         return true;
      }
   }
   return false;
}

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   cin >> n;
   cin >> s;
   compute_hash(s);
   int l = 1 , r = n , ans = 0;
   while (l <= r){
      int mid = (l + r) / 2;
      if(valid(mid)){
         ans = mid , l = mid + 1;
      }
      else{
         r = mid - 1;
      }
   }

   cout << ans << "\n";
}

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

int main()
{
	std::string S, T;
	std::cin >> S >> T;
	int count{};
	for (int i{}; i < 3; i++)
		if (S[i] == T[i])
			count++;
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 256
def main():
    n, d = [int(e) for e in input().split()]
    XY = [[int(e) for e in input().split()] for i in range(n)]

    ans = 0
    for x, y in XY:
        if d ** 2 >= x ** 2 + y ** 2:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 102472
#include<bits/stdc++.h>
using namespace std;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}
const int maxn=1e3+5;
char s[maxn][maxn];
int ans[maxn][maxn],vis[maxn][maxn],n,m,fx,fy,tx,ty;
int dir[4][2]={1,0,-1,0,0,1,0,-1};
struct node
{
    int x,y,step;
};
deque<node> Q;
int main()
{
    n=read(),m=read();
    fx=read(),fy=read();
    tx=read(),ty=read();
    for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			ans[i][j]=-1;
    Q.push_back((node){fx,fy,0});
    while(!Q.empty())
    {
        node nd=Q.front();
		Q.pop_front();
        int x=nd.x,y=nd.y,step=nd.step;
        if(vis[x][y])
			continue;
        vis[x][y]=1;
        ans[x][y]=step;
        for(int i=0;i<4;i++)
        {
            int xx=x+dir[i][0],yy=y+dir[i][1];
            if(xx>0&&xx<=n&&yy>0&&yy<=m&&!vis[xx][yy]&&s[xx][yy]=='.')
                Q.push_front((node){xx,yy,step});
        }
        for(int xx=x-2;xx<=x+2;xx++)
            for(int yy=y-2;yy<=y+2;yy++)
            {
                if(xx>0&&xx<=n&&yy>0&&yy<=m&&!vis[xx][yy]&&s[xx][yy]=='.')
                    Q.push_back((node){xx,yy,step+1});
            }
    }
    if(ans[tx][ty]<0)
		cout<<-1<<endl;
    else
		cout<<ans[tx][ty]<<endl;

    return 0;
}


Measured memory_bytes: 12964
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;

using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<ll, ll> pii;
typedef long double ld;
#define double long double
typedef pair<ld, ld> pld;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

typedef vector<ll> vi;
typedef vector<pii> vpii;
namespace IO {
    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> &a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> &a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> &a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int ll

void solve() {
    int n;
    cin >> n;
    const int INF=1000000000000000000;
    int res = 1;
    vi cur(n);
    cin >> cur;
    if (count(all(cur), 0)) {
        put(0);
        return;
    }
    rep(i, 0, n) {
        int a = cur[i];
        __int128 x = (__int128)a *(__int128) res;
        if (x > INF) {
            put(-1);
            return;
        }
        res *= a;
        if (res > INF) {
            put(-1);
            return;
        }
    }
    put(res);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;
    while (q--) solve();
}



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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

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

    if(s == "Sunny"){
        cout << "Cloudy";
    } else if(s == "Cloudy"){
        cout << "Rainy";
    } else {
        cout << "Sunny";
    }

    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 REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll b,c=0,k=1,n,h,w,m,min=100000000000,ans=0,max=0;
    string s,s2;
    cin >> n;
    VI a(n);
    bool f = false;
    rep(i,n){
        cin >> a[i];
    }
    m = 0;
    while(n){
        c++;
        if(a[m]==2){
            cout << c << endl;
            return 0;
        }
        m = a[m]-1; 
        n--;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1024
import math

def get_pos(a, l):
  return (math.cos(a) * l, math.sin(a) * l)


[a, b, h, m] = list(map(int, input().split()))

(xh, yh) = get_pos((h * 60 + m) * (2 * math.pi) / (12 * 60), a)
(xm, ym) = get_pos(m * (2 * math.pi) / 60, b)
d = math.sqrt((xh - xm) ** 2 + (yh - ym) ** 2)

print(d)


Measured memory_bytes: 9604
#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;
typedef long long ll;
int main()
{
  ll h,w;cin >> h >> w;
  if(h==1||w==1) cout << 1 << "\n";
  else {
    //    ll res = (h*w+(ll)1)/2;
    ll res = ((h+1)/2)*((w+1)/2)+(h/2)*(w/2);
    cout << res << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			C();
		}

		public static void C()
		{
			Scanner cin = new Scanner();
			long n = cin.NextLong();
			long a = cin.NextLong();
			long b = cin.NextLong();
			long c = cin.NextLong();
			long d = cin.NextLong();
			long e = cin.NextLong();

			long[] xx = new long[] { a, b, c, d, e };
			long min = xx.Min();

			long x = n / min + (n % min == 0 ? 0 : 1);
			Console.Write(x + 4);
		}

		
	}

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

		char[] cs = new char[] { ' ' };

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

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 13268
#include <stdio.h>

int main(){
  int N,Q,T;
  long long int S=0LL;
  int A[100002]={},B,C;
  scanf("%d\n",&N);
  for(int i=0;i<N-1;i++){
    scanf("%d ",&T);
    A[T]++;
    S+=(long long int)T;
  }
  scanf("%d\n",&T);
  A[T]++;
  S+=(long long int)T;
  
  scanf("%d\n",&Q);
  for(int i=0;i<Q;i++){
    scanf("%d %d\n",&B,&C);
    S+=(long long int)((C-B)*A[B]);
    A[C]+=A[B];
    A[B]=0;
    printf("%lld\n",S);
  }
  
  return 0;
}
  

Measured memory_bytes: 2124
def triangles(a): 
    n = len(a) 
    a.sort() 
    count = 0
    for i in range(0,n-2):
        k = i + 2
        for j in range(i+1,n): 
            while (k < n and a[i] + a[j] > a[k]): 
                k += 1
            if(k>j): 
                count += k - j - 1
    return count
n=int(input())
a=list(map(int,input().split()))
print(triangles(a))

Measured memory_bytes: 3188
#include<cstdio>
using namespace std;
int main()
{
	long long n,m,ans=0;
	scanf("%lld%lld",&n,&m);
	if(m==0)
	{
		printf("0\n");
		return 0; 
	}
	/*while(n!=0&&m>1)
	{
		m-=2;
		ans++;
		n--;
	}*/

	ans=m-n*2;
	if(ans<0)
	{
		printf("%lld\n",m/2);
		return 0;
	} 
	printf("%lld\n",n+ans/4);
	return 0;
}

Measured memory_bytes: 128
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 = new String[N];
		char[] initial = new char[N];
		long m = 0; long a = 0; long r = 0; long c = 0; long h = 0;

		for(int i=0; i<N; i++) {
			S[i] = sc.next();
			initial[i] = S[i].charAt(0);
			if(initial[i] == 'M') m++;
			else if(initial[i] == 'A') a++;
			else if(initial[i] == 'R') r++;
			else if(initial[i] == 'C') c++;
			else if(initial[i] == 'H') h++;
		}
			long ans =  m*a*r+m*a*c+m*a*h
					+m*r*c+m*r*h+m*c*h
					+a*r*c+a*r*h+a*c*h
					+r*c*h;

			System.out.println(ans);
	}

}


Measured memory_bytes: 50944
s = input()
c = 0
for i in range(0,len(s)):
    if s[i] == 'U' or s[i] == 'D':
        continue
    elif s[i] == 'L':
        if i%2 == 1:
            continue
        else:
            c = 1
    else:
        if i%2 == 0:
            continue
        else:
            c = 1
if c == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
const ll MOD = 1000'000'007LL;
int main()
{
    ll n;
    cin >> n;

    vector<ll> cnts(63, 0);
    rep(i, 0, n)
    {
        ll value;
        cin >> value;

        rep(j, 0, 62)
        if (value&(1LL<<j))
            ++cnts[j];
    }

    ll res = 0;
    ll base = 1;
    rep(i, 0, 62)
    {
        ll nums = cnts[i]*(n-cnts[i])%MOD;
        res += (ll)(base*nums)%MOD;
        res %= MOD;
        base <<= 1;
        base %= MOD;
    }


    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int k, n;
    cin >> k >> n;
    int ma = 0;
    int b[n];
    cin >> b[0];
    rep1(i,n){
        cin >> b[i];
        ma = max(ma, b[i]-b[i-1]);
    } 
    ma = max(ma, k - b[n-1] + b[0]);
    cout << k - ma << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

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

    int N;
    cin >> N;
    map<int, int> mp;
    REP (i, N) {
        int A;
        cin >> A;
        mp[A]++;
    }
    for (auto p : mp) {
        if (p.second > 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 12800
N = int(input())
S = input()

z = []
for i in range(1,N):
  x = S[:i]
  y = S[i:]
  if set(x) & set(y):
    z.append(len(set(x)&set(y)))
  else:
    continue

print(max(z) if len(z) != 0 else 0)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

typedef long long int ll;
typedef long double ld;

int main(){
    ll a,c=0;
    cin >> a;
    ll b[a];
    for (int i=0;i<a;++i){
        cin >> b[i];
        c += b[i];
    }
    sort(b,b+a);
    cout << b[0] << " " << b[a-1] << " " << c << endl;
    
}



Measured memory_bytes: 3240
#include<bits/stdc++.h>
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define int	    int64_t
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,ans=0,w[101],v[101],W;
int dp[3001][3001];
string s, t;
int f(int i , int j){
	if(i==s.size() || j==t.size())
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	int ans = 0;
	if(s[i]==t[j]){
		ans= 1+f(i+1,j+1);
	}else ans=max({ans,f(i+1,j),f(i,j+1)});
	return dp[i][j]=ans;
}
void go(int i , int j){
	if(i==s.size() || j==t.size())
		return;
	if(s[i]==t[j]){
		cout<<s[i];
		go(i+1,j+1);
	}else{
		if(f(i+1,j)>f(i,j+1))
			go(i+1,j);
		else go(i,j+1);
	}
}
void solve(){
	memset(dp,-1,sizeof dp);
	cin>>s>>t;
	f(0,0);
	go(0,0);
}
signed main()
{
    ios
    int test = 1;
    //cin>>test;
    while(test--){
    	solve();
    }
    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<pll> ans;
    vector<ll> v(N, 0);
    FOR(i, N, 1)
    {
        if (K == 0)
        {
            //! 今まで使った頂点全てと辺を結ぶ
            REP(j, i)
            {
                ans.push_back(pll(j, i));
            }
            continue;
        }
        ll mi = 0;
        REP(j, i)
        {
            if (v[mi] < v[j])
                mi = j;
        }
        K -= v[mi];
        REP(j, ans.size())
        {
            if (K >= 0)
                break;
            ll a = ans[j].first;
            ll b = ans[j].second;
            if (a == mi)
            {
                ans.push_back(pll(b, i));
                K++;
            }
            else if (b == mi)
            {
                ans.push_back(pll(a, i));
                K++;
            }
        }
        ans.push_back(pll(mi, i));
        v[mi]++;
        v[i]++;
    }

    if (K > 0)
        cout << -1 << endl;
    else
    {
        cout << ans.size() << endl;
        REP(i, ans.size())
        {
            cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 512
def multy(a,b):
	c = 0
	for i in range(len(a)):
		c += a[i]*b[i]
	return c
N,M = map(int, raw_input().split())
ks = []
for i in range(M):
	ks2 = map(int, raw_input().split())
	ks.append(ks2)
pm = map(int, raw_input().split())
plist = []
for i in ks:
	t = [0]*N
	ini = 1
	for j in i:
		if(ini == 1):
			ini = 0
			continue
		else:
			t[j-1] = 1
	plist.append(t)
slist = []
for i in range(2**N):
	t = []
	for j in range(N):
		t.append(i%2)
		i = i/2
	slist.append(t)
r = 0
for p in plist:
	s2 = []
	for s in slist:
		if(multy(p,s)%2 == pm[r]):
			s2.append(s)
	r = r+1
	slist = s2
print(len(slist))

Measured memory_bytes: 2948
from collections import Counter
N = int(input())
X = []
for i in range(N):
    x,y = map(int,input().split())
    X.append((x,y))
kouho = []
for i in range(N):
    for j in range(N):
        if i==j:continue
        kouho.append((X[i][0]-X[j][0],X[i][1]-X[j][1]))
C = Counter(kouho)
if len(C)==0:print(1)
else:print(N-max(C.values()))

Measured memory_bytes: 3828
a,b,c,x,y,f,t;main(n){while(1){scanf("%d%d%d%d%d",&n,&a,&b,&c,&x);if(!n)exit(0);for(f=t=0;n-->0;t=1){scanf("%d",&y);while(t||x!=y&&f<10001)t=0,f++,x=(a*x+b)%c;}f>10000?f=-1:0;printf("%d\n",f);}}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll N, A, B;
  cin >> N >> A >> B;

  if(A > B){
    swap(A, B);
  }

  ll D = B - A;
  if(D % 2 == 0){
    cout << D / 2 << endl;
  }else{

    cout << min(A-1+(D+1)/2, (N-B)+(D+1)/2) << endl;

  }

  return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    string s; cin >> s;
    cout << min( count( ALL( s ), '0' ), count( ALL( s ), '1' ) ) * 2 << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <set>

using namespace std;

int H, W;
char map[25][25];
int memo[25][25][25][25];

int calc(int sx, int sy, int tx, int ty)
{
	if(sx > tx || sy > ty) return 0;
	if(memo[sx][sy][tx][ty] != -1) return memo[sx][sy][tx][ty];
	
	int g;
	set<int> s;
	for(int x = sx; x <= tx; x++){
		for(int y = sy; y <= ty; y++){
			if(map[x][y] == 'X') continue;
			g = 0;
			g ^= calc(sx, sy, x-1, y-1);
			g ^= calc(x+1, sy, tx, y-1);
			g ^= calc(sx, y+1, x-1, ty);
			g ^= calc(x+1, y+1, tx, ty);
			s.insert(g);
		}
	}
	int ret = 0;
	while(s.count(ret)) ret++;
	return memo[sx][sy][tx][ty] = ret;
}

int main(void)
{
	cin >> H >> W;
	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			cin >> map[x][y];
		}
	}
	
	for(int sx = 0; sx < W; sx++){
		for(int sy = 0; sy < H; sy++){
			for(int tx = 0; tx < W; tx++){
				for(int ty = 0; ty < H; ty++){
					memo[sx][sy][tx][ty] = -1;
				}
			}
		}
	}
	if(calc(0, 0, W-1, H-1)) cout << "First" << endl;
	else cout << "Second" << endl;
	
	return 0;
}


Measured memory_bytes: 4156