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

int main() {
  
  vector<vector<int>> c(3,vector<int>(3));
  for ( int i = 0; i < 3; i++){
    for ( int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }
  
  for ( int i = 0; i < 3; i++){
    c[i][1] -= c[i][0]; c[i][2] -= c[i][0]; c[i][0] = 0;
  }
  for ( int j = 0; j < 3; j++){
    if ( !(c[0][j] == c[1][j] && c[1][j] == c[2][j]) ){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  return 0;
   
}

Measured memory_bytes: 3600
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
template <typename T>
void read(T &x){ 
	T f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	x*=f;
}
const int MAXN = 5e3 + 5;
const int mod = 1e9 + 7;
int head[MAXN] , to[MAXN << 1] , nxt[MAXN << 1] , cnt , n;
void add(int u , int v) {nxt[++cnt] = head[u];to[cnt] = v;head[u] = cnt;}
LL f[MAXN][MAXN] , g[MAXN] , tmp[MAXN] , siz[MAXN];
void dfs(int x , int fa) {
	siz[x] = f[x][1] = 1;
	for (int i = head[x]; i; i = nxt[i]) {
		if(to[i] == fa) continue;
		dfs(to[i] , x);
		for (int j = 1; j <= siz[x] + siz[to[i]]; ++j) tmp[j] = 0;
		for (int j = 1; j <= siz[x]; ++j) {
			for (int k = 0; k <= siz[to[i]]; ++k) {
				tmp[k + j] = (tmp[k + j] + f[to[i]][k] * f[x][j] % mod) % mod;
			}
		}
		for (int j = 1; j <= siz[x] + siz[to[i]]; ++j) f[x][j] = tmp[j];
		siz[x] += siz[to[i]];
	}
	for (int i = 2; i <= siz[x]; i += 2) f[x][0] = (f[x][0] - f[x][i] * g[i] % mod + mod) % mod;
}
int main() {
	read(n);
	for (int i = 1; i < n; ++i) {
		int u , v;
		read(u);read(v);
		add(u , v);add(v , u);
	}
	g[0] = 1;
	for (int i = 2; i <= n; i += 2) g[i] = g[i - 2] * (i - 1) % mod; 
	dfs(1 , 0);
	f[1][0] = -f[1][0];
	printf("%lld" , (f[1][0] % mod + mod) % mod);
	return 0;
}

Measured memory_bytes: 90440
#include <cstdio>
#include <vector>

#define MAX(a,b) ((a)>(b)?(a):(b))

using namespace std;


struct BINNODE {
	int parent;
	int depth;
	int degree;
	int sibling;
	int left;
	int right;
	int height;

	BINNODE () { // default constructor
		parent=-1;
		depth=0;
		degree=0;
		sibling=-1;
		left=-1;
		right=-1;
		height=-1;
	}
};

int heightSearch(vector<BINNODE>& node, int target) {
	if(target == -1) return -1;
	else if(node[target].height!=-1) return node[target].height;
	else return MAX(heightSearch(node,node[target].left),heightSearch(node,node[target].right))+1;
}

int main() {
	int n;
	int i,c;
	int id,left,right;
	vector<BINNODE> node;
	scanf("%d",&n);
	node.resize(n);
	for(i=0; i<n; ++i) {
		scanf("%d%d%d",&id,&left,&right);
		node[id].left=left;
		node[id].right=right;
		if(left==-1 && right==-1) {
			node[id].degree=0;
		} else if(left==-1) {
			node[id].degree=1;
			node[right].parent=id;
			node[right].sibling=-1;
		} else if(right==-1) {
			node[id].degree=1;
			node[left].parent=id;
			node[left].sibling=-1;
		} else {
			node[id].degree=2;
			node[left].parent=id;
			node[right].parent=id;
			node[left].sibling=right;
			node[right].sibling=left;
		}
	}
	for(i=0; i<n; ++i) {
		c=0;
		id=i;
		while(node[id].parent!=-1) {
			++c;
			id=node[id].parent;
		}
		node[i].depth=c;
		node[i].height=heightSearch(node,i);
	}
	for(i=0; i<n; ++i) {
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "
				,i,node[i].parent,node[i].sibling,node[i].degree,node[i].depth,node[i].height);
		if(node[i].parent==-1) {
			printf("root\n");
		} else if (node[i].left==-1&&node[i].right==-1) {
			printf("leaf\n");
		} else {
			printf("internal node\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2732
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int n;
	cin >> n;
	v1 a(n+1);
	vl dp(n+1);
	rep(i, n){
		cin >> a[i+1];
	}
	dp[0] = 1000;
	for(int k = 1; k <=n; k++){
		dp[k] = 0;
		for(int i = 0;i<k-1;i++){
			int m = 999999;
			for(int j = i+1; j<k; j++){
				m = min(m, a[j]);
			}
			dp[k] = max(dp[k], dp[i]/m*a[k]+dp[i]%m);
		}
	}
	ll ans = 0;
	rep(i, n+1) ans = max(ans, dp[i]);
	cout << ans << endl;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>	
#include <utility>
#include <cinttypes>
using namespace std;
int main(){
    int32_t n,m;
    vector<pair<int32_t,int32_t>> a;
    scanf("%d %d",&n,&m);
    a.reserve(n);
    for (int32_t i=0;i<n;i++){
        int32_t tmp1,tmp2;
        scanf("%d %d",&tmp1,&tmp2);
        a.push_back(pair<int32_t, int32_t>(tmp1,tmp2));
    }
    sort(a.begin(),a.end(),[](pair<int32_t,int32_t> x, pair<int32_t,int32_t> y) -> int32_t {return ( x.first < y.first );});
    int32_t i = 0;
    int64_t total = 0;
    while (m > 0){
        int64_t buy_each = min(a[i].second,m);
        total += a[i].first*buy_each;
        m -= buy_each;
        i++;
    }
    printf("%" PRId64 "\n",total);
}

Measured memory_bytes: 1024
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
if x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
n, k = map(int, input().split())

pattern = 0

for i in range(k, n + 2):
    min = (0 + i - 1) // 2 * i
    max = ((n - i) + (1 + n)) // 2 * i
    pattern += max - min + 1
    
pattern %= 10 ** 9 + 7

print(pattern)

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

int main() {
  vector<vector<char>> data(110,vector<char>(110));
  int h,w;
  vector<bool> x(110,false);
  vector<bool> y(110,false);
  cin>>h>>w;
  rep(i,h){
  rep(j,w){
  cin>>data[i][j];
  }
  }
  rep(i,h){
  rep(j,w){
  if(data[i][j]=='#'){
  x[i]=true;
    y[j]=true;
  }
  }
  }
  rep(i,h){
  if(x[i]){
  rep(j,w) if(y[j])cout<<data[i][j];
    cout<<endl;
  }
  }
}

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

const int N=2e5+20,MOD=1e9+7;

int n,k,f[N],ie[N],ans;

int mul(int a,int b) {return (1ll*a*b)%MOD;}

int power(int a,int b)
{
	int num=a,ans=1;
	while(b)
	{
		if(b&1) ans=mul(ans,num);
		b>>=1;
		num=mul(num,num);
	}
	return ans;
}

int inverse_euler(int n)
{
	return power(n,MOD-2);
}

int ncr(int n,int r)
{
	return mul(f[n],mul(ie[r],ie[n-r]));
}

void precompute()
{
	f[0]=1;
	for(int i=1;i<N;i++) f[i]=mul(f[i-1],i);
	for(int i=0;i<N;i++) ie[i]=inverse_euler(f[i]);
}

int main()
{
	precompute();
	cin>>n>>k;
	k=min(k,n-1);

	for(int i=0;i<=k;i++)
		ans=(ans+mul(ncr(n,i),ncr(n-1,n-i-1)))%MOD;
	printf("%d",ans);
}

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

using namespace std;


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

	map<int, int> cnt;

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

	int ans = 0;
	for (pair<int, int> a : cnt) {
		ans += a.second % 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
import java.util.*;
class Main{
    Main(){
	Scanner sc =new Scanner(System.in);
	int[] c={1,5,10,50,100,500};
	int x=0;
	for(int i=0;i<6;i++){
	    int a=sc.nextInt();
	    x=x+(c[i]*a);
	}
	int y=0;
	if(x>=1000)y=1;
	System.out.println(y);
    }
    public static void main (String[]arg){
	new Main();
    }
}

Measured memory_bytes: 17276
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int A, B;
  int ans = 0;
  string s;

  cin >> A >> B;

  ans = (A -1) * (B-1);
  cout << ans << endl;

}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int s = W.Sum();
		int t = 0;
		int ans = s;
		for(int i=0;i<N;i++){
			s -= W[i];
			t += W[i];
			ans = Math.Min(ans, Math.Abs(s - t));
		}
		Console.WriteLine(ans);
	}
	int N;
	int[] W;
	public Sol(){
		N = ri();
		W = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    string s;
    cin >> s;
    map<char, int> l;
    REP(i, 4) l[s[i]]++;
    bool res = true;
    if(l.size()!=2) res =false;
    else {
        for(auto x: l) if(x.second!=2) res =false;
    }
    if(res) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import Data.List

cannotCreateTriangle [a, b, c] = c >= a + b

readTriangle list = do
    line <- getLine
    let elem = sort (map read (words line)) :: [Int]
    if cannotCreateTriangle elem then return list
    else readTriangle (elem : list)

calculateDiscriminant [a, b, c] = c*c - b*b - a*a

main = do
    tris <- readTriangle []
    let dets = map calculateDiscriminant tris
    let res = [(length dets),
               (foldr (\x acc -> if x == 0 then (acc+1) else acc) 0 dets),
               (foldr (\x acc -> if x < 0 then (acc+1) else acc) 0 dets),
               (foldr (\x acc -> if x > 0 then (acc+1) else acc) 0 dets)]
    putStrLn (unwords (map show res))



Measured memory_bytes: 4112
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  cout.precision(12);

  long A, B, C;
  cin >> A >> B >> C;

  cout << min((B / A), C) << endl;

  return 0;
}


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

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    int count1=0,count2=0;
    for(char i:s){
        if(i=='R')count1++;
        else count2++;
    }
    if(count1>count2) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	int len=s.size();
	if(s[0]!=s[len-1])
	{
		if(len%2)cout<<"First";
		else
		cout<<"Second";
	}
	else
	{
		if(len%2)cout<<"Second";
		else
		cout<<"First";
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#define FORi(N) for(int i=0;i<N;++i)
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,X;
  cin>>N>>X;
  vector<ll> x(N);
  FORi(N){
    cin>>x[i];
    x[i]-=X;
  }
  ll ans=x[0];
  FORi(N){
    ans=gcd(ans,x[i]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
# ABC141D - Powerful Discount Tickets
from heapq import heapify, heappop, heappush

pop_max, push_max = lambda heap: -heappop(heap), lambda heap, x: heappush(heap, -x)


def main():
    N, M = map(int, input().split())
    A = [-i for i in map(int, input().split())]
    heapify(A)
    for _ in range(M):
        x = pop_max(A)
        push_max(A, x // 2)
    ans = -sum(A)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14180
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)
 
typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;
 
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
 
int main() {
    int N,K; cin>>N>>K;
    int h[N]; REP(i,N) cin>>h[i];
    sort(h,h+N);
    i64 tmp, ans = 1e14;
    REP(i,N-K+1) {
        tmp = h[i+K-1]-h[i];
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, k, c;
  double p=0;
  map<ll, ll> x;
  cin >> n >> k;

  if (n >= k){
	p += ((double)(n-k + 1) / n);
  }

  forll(i, 0, min(n, k-1)){
	forll(j, 1, k){
	  if ((i + 1) * pow(2, j) >= k){
		x[i] = j;
		break;
	  }
	}
  }
  forll(i, 0, min(n, k-1)){
	p += (pow(0.5, (double)x[i]) / n);
  }
  cout << setprecision(20) << p << endl;
  
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int h,w,i;
string s[200];
int main()
{
  for(cin>>h>>w;i<2*h;i+=2)cin>>s[i],s[i+1]=s[i];
  for(i=0;i<2*h;i++)cout<<s[i]<<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	S := next()

	c := 0
	for _, r := range S {
		if r == '1' {
			c++
		}
	}

	fmt.Println(c)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;
ll const MOD = 1e9+7;
ll k;

ll calcMinus(vector<ll> plus, vector<ll> minus) {
  sort(plus.begin(), plus.end());
  sort(minus.begin(), minus.end(), greater<ll>());

  ll ans = 1;

  rep(i, k) {
    ans = ans * minus[i] % MOD;
    if (ans < 0) ans += MOD;
  }
  return ans;
}

ll calcPlus(vector<ll> plus, vector<ll> minus) {
  sort(plus.begin(), plus.end(), greater<ll>());
  sort(minus.begin(), minus.end());

  ll ans = 1;
  ll indexP = 0;
  ll indexM = 0;

  rep(i, k) {
    if (i == 0 && k > ll(minus.size()) && k % 2 == 1) {
      ans = ans * plus[indexP] % MOD;
      indexP++;
      continue;
    }

    if (k-i < 2 || ll(minus.size()) - indexM < 2) {
      ans = ans * plus[indexP] % MOD;
      indexP++;
      continue;
    }

    if (ll(plus.size()) - indexP < 2) {
      ans = ans * minus[indexM] % MOD * minus[indexM + 1] % MOD;
      indexM += 2;
      i += 1;
      continue;
    }

    if (plus[indexP] * plus[indexP + 1] >= minus[indexM] * minus[indexM + 1]) {
      ans = ans * plus[indexP] % MOD * plus[indexP + 1] % MOD;
      indexP += 2;
      i += 1;
      continue;
    } else {
      ans = ans * minus[indexM] % MOD * minus[indexM + 1] % MOD;
      indexM += 2;
      i += 1;
      continue;
    }

  }
  return ans;
}

int main() {
  ll n;
  cin >> n >> k;

  vector<ll> plus, minus;

  rep(i, n) {
    ll a;
    cin >> a;
    if (a >= 0) plus.push_back(a);
    else minus.push_back(a);
  }

  ll ans = 1;

  if (k == n) {
    rep(i, ll(plus.size())) ans = ans * plus[i] % MOD;
    rep(i, ll(minus.size())) ans = ans * minus[i] % MOD;
    if (ans < 0) ans = ans + MOD;
  } else if (ll(plus.size() == 0) && k % 2 == 1) {
    ans = calcMinus(plus, minus);
  } else {
    ans = calcPlus(plus, minus);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6416
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  for (int i = k; i < n; ++i) {
    bool ans = true;
    if (a[i] <= a[i - k]) ans = false;
    cout << (ans ? "Yes" : "No") << endl;
  }
  
}

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

const int MAXN = 110 * 110 * 2;
const int INF = std::numeric_limits<int>::max();
const int MAXM = MAXN * 10;
int head[MAXN], nxt[MAXM], to[MAXM], val[MAXM], tot = 1;
int S, T, idx;
void addedge(int b, int e, int v) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e; val[tot] = v;
	nxt[++tot] = head[e]; to[head[e] = tot] = b; val[tot] = 0;
}
int dis[MAXN]; std::queue<int> q;
bool bfs() {
	memset(dis, 0, idx + 1 << 2);
	q.push(S); dis[S] = 1;
	while (!q.empty()) {
		int t = q.front(); q.pop();
		for (int i = head[t]; i; i = nxt[i])
			if (val[i] && !dis[to[i]]) {
				q.push(to[i]);
				dis[to[i]] = dis[t] + 1;
			}
	}
	return dis[T] > 0;
}
int dinic(int u, int minv) {
	if (!minv || u == T) return minv;
	int res = 0, t;
	for (int & i = head[u]; i; i = nxt[i])
		if (val[i] && dis[to[i]] == dis[u] + 1 && (t = dinic(to[i], std::min(minv, val[i])))) {
			val[i] -= t;
			val[i ^ 1] += t;
			res += t;
			minv -= t;
			if (!minv) break;
		}
	if (!res) dis[u] = -1;
	return res;
}
int tmp;
int flow() {
	static int te[MAXN];
	int ans = 0;
	memcpy(te, head, idx + 1 << 2);
	while (bfs()) {
		ans += dinic(S, INF);
		if (ans > tmp) break;
		memcpy(head, te, idx + 1 << 2);
	}
	return ans;
}
char mat[110];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	int H, W; std::cin >> H >> W;
	S = 0, T = idx = H + W + 1;
	for (int i = 1; i <= H; ++i) {
		std::cin >> mat + 1;
		for (int j = 1; j <= W; ++j)
			if (mat[j] != '.') {
				if (mat[j] == 'S')
					addedge(S, i, INF), addedge(S, j + H, INF);
				else if (mat[j] == 'T')
					addedge(i, T, INF), addedge(j + H, T, INF);
				else
					addedge(i, j + H, 1), addedge(j + H, i, 1);
				tmp += mat[j] == 'o';
			}
	}
	int ans = flow(); if (ans > tmp) ans = -1;
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 768
#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 A,B,C,X;
	cin>>A>>B>>C>>X;
	int ans=0;
	rep(i,A+1){
		rep(j,B+1){
			rep(k,C+1){
				if(i*500+j*100+k*50==X){
					ans+=1;
				}
			}
		}
	}
	cout<<ans<<endl;
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
#coding: utf-8
from collections import Counter
N = int(input())
l = list(map(int,input().split()))
if len(set(l)) > 1:
  o, e = [], []
  for i in range(N):
    if i % 2==0:
      e.append(l[i])
    else:
      o.append(l[i])
  oc, oe = Counter(o).most_common(2), Counter(e).most_common(2)
  print(len(l) - oc[0][1] - oe[0][1] if oc[0][0] != oe[0][0] else len(l) - max(oc[0][1] + oe[1][1], oc[1][1] + oe[0][1]))

else:
  print(len(l) // 2)

Measured memory_bytes: 16228
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint ans = 0, x = 0;
	for(int i = 1; i <= n; i++){
		ans += max(0LL, x-a[i]);
		x = max(x, a[i]);
	}
	cout << ans << endl;
	
	return 0;
}

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

int main()  {
    using namespace std;

    int n;
    cin >> n;

    vector<int> a;

    for (int i=0; i < n; i++) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    
    cout << a[0];  
    for (int i=1; i<n; i++) {
        cout << ' ' << a[i];    
    }
    cout << endl;

    for (int i=1; i<n; i++) {
        int v = a[i];
        int j = i-1;
        while (j >= 0 && a[j] > v)
        {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;

        cout << a[0];  
        for (int i=1; i<n; i++) {
            cout << ' ' << a[i];    
        }
        cout << endl;
    }
}


Measured memory_bytes: 3088
def solve(k):
  def gcd(a, b):
    if a < b:
      a,b = b,a
    while b:
      a, b = b, a%b
    return a

  ans = 0
  for a in range(1, k+1):
    for b in range(1, k+1):
      for c in range(1, k+1):
        ans += gcd(gcd(a,b),c)
  return ans

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', 'i8(i8)')(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    print(solve(int(input())))

Measured memory_bytes: 27240
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int D[110][2];
    rep(i, N) {
        cin >> D[i][0] >> D[i][1];
    }
    int len = 0;
    rep(i, N) {
        if(D[i][0] == D[i][1]) len++;
        else len = 0;
        if(len >= 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<double,int>;

int main(){
    ll q,h,s,d;
    cin >> q >> h >> s >> d;
    int n;
    cin >> n;
    h = min(h,q*2);
    s = min(s,h*2);
    d = min(d,s*2);

    if(n%2==0){
        cout << n/2*d << endl;
        return 0;
    } else {
        cout << n/2*d + s << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	ll out=0;
	vp in(n);
	rep(i,n)cin>>in[i].first>>in[i].second;
	ll t=in[0].first;
	rep(i,n)in[i].first-=t;
	rep(i,n+1){
		ll w=m-i*t;
		if(w<0)continue;
		vvi dp(i+1,vi(500));
		rep(j,n)for(int k=i-1;k>=0;k--)rep(l,500)if(l+in[j].first<500)
			dp[k+1][l+in[j].first]=max(dp[k+1][l+in[j].first],dp[k][l]+in[j].second);
		ll ma=0;
//		rep(j,w+1)cout<<" "<<dp[j];cout<<endl;
		rep(j,min(w+1,500LL))ma=max(ma,dp[i][j]);
		out=max(out,ma);
	}
	cout<<out<<endl;
}







Measured memory_bytes: 692
#include<bits/stdc++.h>
using namespace std;
int a,b,n,i,s;
int main()
{
	cin>>n>>a>>b;
	for(i=1;i<=n;i++)
	{
		int x=i,c=0;
		while(x!=0){
			c+=x%10;
			x/=10;
		}
		if(c>=a&&c<=b)s+=i;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<long,long > pii;
typedef pair<long,pii > piii;
typedef vector<long long >   VI;
#define sc1(x) scanf("%lld",&x);
#define sc2(x,y) scanf("%lld%lld",&x,&y);
#define sc3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z);
#define pb push_back
#define mp make_pair
#define ini(x,val) memset(x,val,sizeof(x));
#define fs first
#define sc second
#define MOD 1000000007
#define inf 999999999999999ll   //long long inf
#define PI 3.1415926535897932384626

#define gcd __gcd
#define tr(contaner, it)  for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define PrintCont(cont) {cout<<("\n----------------\n");\
for(typeof(cont.begin()) it = cont.begin();it!=cont.end();++it) cout<<*it<<" ";cout<<("\n----------------\n");}
#define all(v) v.begin(),v.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

int main()
{
	ll n,temp;
	VI vect;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>temp;
		vect.pb(temp);
	}

	sort(vect.begin(),vect.end());

	ll ref=vect[n-1],sum[1000010],ans;
	ini(sum,0);
	sum[0]=vect[0];
	for(int i=1;i<n;i++)
	{
		sum[i]=vect[i]+sum[i-1];
	}
	for(int i=n-1;i>=0;i--)
	{
		if(vect[i]>2*sum[i-1])
		{
			ans=n-i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8948
#include<stdio.h>

#define N 500000
#define S 1000000000

void Sort(int, int);
void Merge(int, int, int);
int A[N], count=0;

int main(void){
int n, i;

scanf("%d", &n);
for(i=0; i < n; i++){
scanf("%d", &A[i]);
}
//printf("\n");

Sort(0, n);

for(i=0; i < n; i++){
printf("%d", A[i]);
if(i < n-1)printf(" ");
}

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

void Sort(int left, int right){
int mid;
if(left+1 < right){
mid = (left + right) / 2;
Sort(left, mid);
Sort(mid, right);
Merge(left, mid, right);
}
}

void Merge(int left, int mid, int right){
int n1, n2, i, j, k;
n1 = mid-left;
n2 = right - mid;
int l[n1], r[n2];

for(i=0; i<n1; i++) l[i] = A[left + i];
for(i=0; i<n2; i++) r[i] = A[mid + i];

l[n1] = S;
r[n2] = S;
i=0;
j=0;

for(k=left; k<right; k++){
if(l[i]<=r[j]){
A[k] = l[i];
i++;
}
 else{
A[k] = r[j];
j++;
}
count++;
}
}

Measured memory_bytes: 4508
#include <iostream>
#include <cstdlib>
 
using namespace std;
// https://qiita.com/Clpsplug/items/81fe12400d4093a8fb5a
 
int main() {
    string S;
    cin >> S;

    int counter = 0;
    int max_counter = 0;
    int N = S.length();
    for (int i = 0; i < N; i++) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            counter++;
            if (max_counter < counter) {
                max_counter = counter;
            }
        } else {
            if (max_counter < counter) {
                max_counter = counter;
            }
            counter = 0;
        }
    }

    cout << max_counter << endl;
}

Measured memory_bytes: 3152
# 146A
# 今日の曜日を表す文字列 S が与えられます。
# Sは SUN,MON,TUE,WED,THU,FRI,SAT のいずれかであり、
# それぞれ日曜日、月曜日、火曜日、水曜日、木曜日、金曜日、土曜日を表します。
# 次の日曜日 (あす以降) が何日後か求めてください。

# 入力: 入力は以下の形式で標準入力から与えられる。
# S
# 出力: 次の日曜日が何日後か出力せよ。

S = input()
if S == 'SAT':
    result = 1
elif S == 'FRI':
    result = 2
elif S == 'THU':
    result = 3
elif S == 'WED':
    result = 4
elif S == 'TUE':
    result = 5
elif S == 'MON':
    result = 6
elif S == 'SUN':
    result = 7

print(result)

Measured memory_bytes: 8972
program answer
  implicit none

  integer(8) :: N, i, j, k, count, eg(10000)
  read(*,*) N
  eg=0
  do i = 1, 100
     do j = 1, 100
        do k= 1, 100
           if(i**2+j**2+k**2+i*j+j*k+k*i<=10000) then
              eg(i**2+j**2+k**2+i*j+j*k+k*i)=eg(i**2+j**2+k**2+i*j+j*k+k*i)+1
           end if
        end do
     end do
  end do

 
  do i = 1, N
     write(*,*) eg(i)
  end do
  stop
 end program answer

Measured memory_bytes: 2740
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

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

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


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


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    sort(H.begin(), H.end());
    int ans = *max_element(H.begin(), H.end());
    for (int i = 0; i <= N - K; i++)
    {
        ans = min(ans, abs(H[i] - H[K - 1 + i]));
    }
    cout << ans << endl;

    return 0;
}

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

int main(void)
{
    bool possible = false;
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
        if (n % i == 0 && n / i <= 9) possible = true;
    }

    if (possible) cout << "Yes\n";
    else cout << "No\n";
}

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

typedef long long ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";
#define pb push_back

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
    for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
    os << "("; os << v.first << ", " << v.second << ")"; return os;
}
void go() {
    cin.tie(nullptr) -> sync_with_stdio(false);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
}
const int N = 1e5 + 5;
vector<vector<int>> parent(N);
vector<int> vis(N),dp(N);
void dfs(int node) {
    vis[node] = 1;
    for (int x : parent[node]) {
        if (!vis[x]) {
            dfs(x);
        }
        dp[node] = max(dp[node], dp[x] + 1);
    }
}
int32_t main() {
    go();
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        parent[y].push_back(x);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            dfs(i);
        }
        ans = max(ans, dp[i]);
    }
    cout << ans;
}

Measured memory_bytes: 13860
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    int n;
    cin>>n>>s;
    int r=0;
    for(int i=0; i<s.length(); i++)
    {
    	if(s[i]!=s[i+1])r++;
	}
	cout<<r<<endl;
    
    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int f(int x){
  int res = 0;
  while(x > 0){
	res += x%10;
	x /= 10;
  }
  return res;
}

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

  int N;
  cin >> N;
  int ans = 1e9;
  FOR(i,1,N){
	int j = N - i;
	mini(ans, f(i) + f(j));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,k;
vi dp,a;

int main(){
	cin>>n>>k;
	dp=vi(k+1);
	a=vi(n);
	for(auto &i:a) cin>>i;
	for(int i=0;i<=k;i++) for(int j=0;j<n;j++) if(i-a[j]>=0&&!dp[i-a[j]]) dp[i]=1;
	cout<<(dp[k]?"First":"Second")<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		long ans = Long.parseLong(sc.nextLine());
		Main main = new Main();
		for (int i = 0; i < n - 1; i++) {
			long let = Long.parseLong(sc.nextLine());
			ans =ans / main.GCD(ans, let) * let;
		}
		System.out.println(ans);
		sc.close();
	}

	public long GCD(long num1, long num2) {
		if (num2 == 0) {
			return num1;
		} else {
			return GCD(num2, num1 % num2);
		}
	}
}

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    for (int i = 1; i < N; i++) {
        bool memory_left[150] = {false};
        bool memory_right[150] = {false};
        int counter = 0;
        string left_S = S.substr(0, i);
        string right_S = S.substr(i, N - i);
        for (int j = 0; j < i; j++) {
            memory_left[int(left_S[j])] = true;
        }
        for (int j = 0; j < N - i; j++) {
            memory_right[int(right_S[j])] = true;
        }
        for (int j = 0; j < 150; j++) {
            if (memory_left[j] && memory_right[j]) {
                counter++;
            }
        }
        ans = max(ans, counter);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
const int N = 1e5+2;
signed main()
{
    fast;
    int n;
    cin>>n;
    int g = 0;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        g = __gcd(g,x);
    }
    cout<<g;
    return 0;
}

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

int main()
{
    int N, K, Q;
    cin >> N >> K >> Q;

    vector<int> Points(N+1, K-Q);
    vector<int> ids(Q);
    for(int i=0; i<Q; i++) {
        cin >> ids[i];
    }
    for (int i=0; i<Q; i++) {
        Points[ids[i]] += 1;
    }

    for (int i=1; i<Points.size(); i++) {
        if (Points[i] > 0) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
def nsertionSort(A, N): #N個の要素を含む0-オリジンの配列A
    print(" ".join(map(str,A)))
    for i in range(1,N,1):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j-=1
            A[j+1] = v
        print(" ".join(map(str,A)))

if __name__ == "__main__":
    N = int(input())
    A = list(map(int,input().split()))
    nsertionSort(A,N)


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NQ = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var s = Console.ReadLine();

            var ruiseki = new int[NQ[0]];
            ruiseki[0] = 0;
            for (int i = 0; i < NQ[0] - 1; i++)
            {
                ruiseki[i + 1] = ruiseki[i] + ((s[i] == 'A' && s[i + 1] == 'C') ? 1 : 0);
            }

            for(int i=0;i<NQ[1];i++)
            {
                var lr = Console.ReadLine().Split().Select(x => int.Parse(x)-1).ToArray();
                Console.WriteLine(ruiseki[lr[1]] - ruiseki[lr[0]]);
            }

        }
    }
}



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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long int lli;

int main()
{
	fio;
	string s;
	cin>>s;
	string temp=s.substr(1,s.length()-1);
	int f=1;
	for(int i=0;i<temp.length();i++)
	{
		if(temp[i]!='9')
		{
			f=0;
			break;
		}
	}
	int sum=0;
	for(int i=0;i<s.length();i++)
	{
		sum+=s[i]-'0';
	}
	if(f)
	{
		cout<<sum<<endl;
	}
	else cout<<s[0]-'0'-1+9*(s.length()-1)<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

char s[185][186];
int sum[186][186];
int dp1[2][185][185][186];
int dp2[2][185][185][186];

bool check(int x1, int y1, int x2, int y2) {
    int c = sum[x2][y2] - sum[x2][y1] - sum[x1][y2] + sum[x1][y1];
    return (c == 0) || (c == (x2 - x1) * (y2 - y1));
}

int main() {
    int h, w, i, j, k, l;
    
    scanf("%d %d", &h, &w);
    
    for (i = 0; i < h; i++) scanf("%s", s[i]);
    
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
            if (s[i][j] == '#') sum[i + 1][j + 1]++;
        }
    }
    
    if (check(0, 0, h, w)) {
        puts("0");
        
        return 0;
    }
    
    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            int r = w, d = h;
            
            for (k = i + 1; k <= h; k++) {
                while (r > j && !check(i, j, k, r)) r--;
                
                dp1[0][i][j][k] = r;
            }
            
            for (k = j + 1; k <= w; k++) {
                while (d > i && !check(i, j, d, k)) d--;
                
                dp2[0][i][j][k] = d;
            }
        }
    }
    
    for (i = 1; i < 20; i++) {
        for (j = 0; j < h; j++) {
            for (k = 0; k < w; k++) {
                for (l = j + 1; l <= h; l++) {
                    int r = dp1[0][j][k][l];
                    
                    if (r == w) {
                        dp1[1][j][k][l] = r;
                    } else {
                        dp1[1][j][k][l] = dp1[0][j][r][l];
                    }
                }
                
                for (l = k + 1; l <= w; l++) {
                    int d = dp2[0][j][k][l];
                    
                    if (d == h) {
                        dp2[1][j][k][l] = d;
                    } else {
                        dp2[1][j][k][l] = dp2[0][d][k][l];
                    }
                }
                
                for (l = j + 1; l <= h; l++) {
                    int r = dp1[1][j][k][l];
                    
                    while (r < w && dp2[1][j][k][r + 1] >= l) r++;
                    
                    dp1[0][j][k][l] = r;
                }
                
                for (l = k + 1; l <= w; l++) {
                    int d = dp2[1][j][k][l];
                    
                    while (d < h && dp1[1][j][k][d + 1] >= l) d++;
                    
                    dp2[0][j][k][l] = d;
                }
            }
        }
        
        if (dp1[0][0][0][h] == w || dp2[0][0][0][w] == h) {
            printf("%d\n", i);
            
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 99840
#include<bits/stdc++.h>
using namespace std;
#define Y cout<<"YES"<<endl;
#define N cout<<"NO"<<endl;
#define tc int t; cin>>t; while(t--)
#define eki int n; cin>>n;
#define loop for(int i=0; i<n; i++)
int main()
{  
    int n, k, ans=0;
    cin>>n>>k;
     int arr[n];
     for(int i=0; i<n; i++)
     {
       cin>>arr[i];
     }
     sort(arr, arr+n);
     for(int i=0; i<k; i++)
     {
         ans=ans+arr[i];
     }
     cout<<ans<<endl;
}




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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    map<int, int> mp;
    for (int i = 0; i < n; i++)
        mp[a.at(i)]++;

    int answer = 0;
    for (auto x : mp)
    {
        int number = x.first, count = x.second;
        if (count >= number)
        {
            answer += count - number;
        }
        else
        {
            answer += count;
        }
    }
    cout << answer << endl;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, m;

struct Edge {
    int to, next;
} edges[maxn];

int tot = 1, head[maxn];

void addEdge(int u, int v) {
    edges[++tot] = {v, head[u]};
    head[u] = tot;
}

int in[maxn], dp[maxn];

int main() {
    int u, v;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        scanf("%d%d", &u, &v);
        addEdge(u, v);
        in[v]++;
    }

    queue<int> q;
    for (int i = 1; i <= n; i++) if (!in[i]) q.push(i);

    int res = 0;
    while (!q.empty()) {
        u = q.front();
        q.pop();
        for (int i = head[u]; i; i = edges[i].next) {
            v = edges[i].to;
            dp[v] = max(dp[v], dp[u] + 1);
            in[v]--;
            if (!in[v]) q.push(v);
        }
    }

    for (int i = 1; i <= n; i++) res = max(res, dp[i]);

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


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


int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    
    int pay[3]={0};
    
    pay[0] = A*X+B*Y;
    
    pay[1] = C*2 * max(X,Y);
    
    if(X>Y){
        pay[2] = A*(X-Y)+C*2*Y;
    }
    else {
        pay[2] = B*(Y-X)+C*2*X;
    }
    
    cout << min(pay[0],min(pay[1],pay[2])) << endl;
}


Measured memory_bytes: 256
while True:
    (m,f,r) = [int(i) for i in input().split()]
    if m == f == r == -1: 
        break

    total = m + f 
    if m == -1 or f == -1 or total < 30: 
        print('F')
    elif total < 50 and r < 50: 
        print('D')
    elif total < 65: 
        print('C')
    elif total < 80: 
        print('B')
    else:
        print('A')

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    rep(i, 0, n) {
        cin >> a[i];
        sum += a[i];
    }
    sum -= n;
    cout << sum << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

const int MAXN = 10001;

vector<int> f(MAXN, 0);

inline void precalc() {
	for (int x = 1; x * x <= MAXN; x++) {
		for (int y = 1; y * y <= MAXN; y++) {
			for (int z = 1; x * x + y * y + z * z + x * y + y * z + z * x < MAXN; z++) {
				f[z * z + y * y + x * x + x * y + y * z + z * x]++;
			}
		}
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	precalc();
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cout << f[i] << '\n';
	}
}


Measured memory_bytes: 3632