akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int n, A[50];

int solve(int i, int m){
    if(m == 0) return 1;
    if(i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main(){
    int q, M, i;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &M);
        if(solve(0, M)) printf("yes\n");
        else printf("no\n");
    }
    
    return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    int a=1;
    rp(i,n){
        a = (2*a>a+k?a+k:2*a);
    }
    cout << a << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int k, x; cin >> k >> x;
	for (int i = x - k + 1; i <= x + k - 1; i++) {
		cout << i << " ";
	}
	return 0;
}


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

int main() {
  vector<char>s(6);
  for(int i=0;i<6;i++)cin>>s[i];
  if(s[0]==s[5]&&s[1]==s[4]&&s[2]==s[3])cout<<"YES";
  else cout<<"NO";
  cout<<endl;
}


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

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

  int jpy = 0;
  double btc = 0.0;
  for (int i = 0; i < n; i++) {
    double x;
    string u;
    cin >> x >> u;

    if (u == "JPY") {
      jpy += x;
    }
    else if (u == "BTC") {
      btc += x;
    }
  }

  cout << jpy + btc * 380000.0 << endl;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
s = gets.chomp.to_s

if n % 2 != 0
    puts 'No'
else
    m = n/2
    ans = s.scan(/.{1,#{m}}/)

    if ans[0] == ans[1]
        puts 'Yes'
    else
        puts 'No'
    end
end



Measured memory_bytes: 1788
#include <iostream>
#include<cstring>
#include<string>
#include<bits/stdc++.h>
using namespace std;
char miku[105];

int main()
{
    gets(miku); 
    int rin=strlen(miku);
    cout<<miku[0]; 
    for(int i=1; i<rin; i++)
        if(miku[i]==' ')   
            cout<<miku[i+1];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
using namespace std;
 int main(){
 string n;
 while(1){
 cin >> n; 
if (n == "0") break;
 int a=0,b=0,i;
 for(i=0 ;i < n.length(); ++i){
 a=n[i]-'0';
 b=b+a;
 } 
cout << b << endl;
 }
 return 0;
 } 

  

 



 

 



Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

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

ll modinv(ll a,ll mod){
  return modpow(a,mod-2,mod);
}

const int MAX=510000;
const int MOD=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  rep(i,MAX){
    if(i>1){
      fac[i]=fac[i-1]*i%MOD;
      inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
      finv[i]=finv[i-1]*inv[i]%MOD;
    }
  }
}

ll COM(int n,int k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
 
int main(){
  int N,M;
  cin>>N>>M;
  COMinit();
  map<int,int> X;
  if(M==1){
    cout<<1<<endl;
    return 0;
  }
  rep(roop,40){
    rep(i,sqrt(M)){
      if(M%(i+2)==0){
        M/=(i+2);
        X[i+2]++;
        break;
      }
    }
  }
  if(M>1) X[M]++;
  auto itr=X.begin();
  ll ans=1;
  rep(i,X.size()){
    ans=(ans*COM((itr->second)+N-1,N-1))%MOD;
    itr++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int a, b;
  cin >> a>>  b;
  
  if(max(a, b) > min(a,b)){
    cout << 2*max(a, b) -1 << endl;
  }else{
    cout << 2*max(a,b) << endl;
  }

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring> 
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i<=b;i--)
using namespace std;
int a[110000];
const int mo=1e9+7;
int main()
{
	int n;
	scanf("%d",&n);
	int ans=1,lst=1;
	for(int i=1,num=1;num<=n;i++,num++)
	{
		int x;
		scanf("%d",&x);
		a[num]=x;
		while (x<i*2-2) i--;
		//if (a[num-1]==1 && a[num]==2) ans=ans*2; else
		ans=(long long)ans*i%mo;
		if (x==i*2-2) i--;
	}	
	printf("%d\n",ans);
}

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

int main(){
	int n, m; scanf("%d%d", &n, &m);

	int f[n+1], *c[n+1], *s[n+1];
	
	for(int i=0;i<=n;++i){
		s[i] = new int[n+1](), c[i] = new int[n+1]();
		memset(s[i], 0, sizeof(int)*(n+1)), memset(c[i], 0, sizeof(int)*(n+1));
		s[i][0] = c[i][0] = 1;
		for(int j=1;j<=i;++j){
			s[i][j] = (s[i-1][j-1] + 1ll*(j+1)*s[i-1][j])%m;
			c[i][j] = (c[i-1][j-1] + c[i-1][j])%m;
		}
	}
	
	auto qpow = [](int x, int k, int m){
		int res = 1;
		while(k){
			if(k&1) res = 1ll*res*x%m;
			x = 1ll*x*x%m;
			k >>= 1;
		}
		return res;
	};
	
	int ans = 0;
	
	for(int i=0;i<=n;++i){
		f[i] = 0;
		int pw22 = qpow(2, qpow(2, n-i, m-1), m);
		int pw2 = qpow(2, n-i, m), pw2j = 1;
		for(int j=0;j<=i;++j){
			f[i] = (f[i] + 1ll*s[i][j]*pw2j%m*pw22)%m;
			pw2j = 1ll* pw2j*pw2%m;
		}
		int tmp = 1ll*c[n][i]*f[i]%m;
		if(i&1) tmp = m - tmp;
		ans = (ans + tmp)%m;
	}
	
	printf("%d\n", ans);
	
	return 0;
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 6005;

int n, P, f[N][2 * N];

void solve() {
	read(n), read(P), n *= 3;
	f[0][N] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = -i / 2 + N; j <= i + N; ++j) {
			f[i + 1][j + 1] = (f[i + 1][j + 1] + f[i][j]) % P;
			f[i + 2][j - 1] = (f[i + 2][j - 1] + 1ll * f[i][j] * (i + 1)) % P;
			f[i + 3][j] = (f[i + 3][j] + 1ll * f[i][j] * (i + 1) % P * (i + 2)) % P;
		}
	}
	int ans = 0;
	for (int j = N; j <= n + N; ++j) {
		ans = (ans + f[n][j]) % P;
	}
	print(ans);
}

int main() {
	int T = 1;
	// read(T);
	while (T--) {
		solve();
	}
}


Measured memory_bytes: 133132
import itertools

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

#隣接行列
path=[[False]* n for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True

ans = 0

for i in itertools.permutations(list(range(n))):
	#頂点１が始点
	if i[0]==0:
		# 生成した順列の中をさらにループ
		for j in range(n):
			# n - 1 まで続いたら条件を満たすパスが存在する
			if j == n-1:
				ans+=1
				break
			# i[j] から i[j + 1] に行くパスがなければ終了
			if not path[i[j]][i[j + 1]]:
				break
print(ans)


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

int main() {
    const int ARRAY_LENGTH = 20;
    char a[ARRAY_LENGTH] = "";
    cin >> a;
    for (int i = ARRAY_LENGTH; i > 0; i--) {
        if (a[i-1] == 0) {
           continue;
        }
        cout << a[i-1];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1132
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,a,b,x;

int main(){
  ll ans=0;
  cin >> a >> b >> n;
  
  x=b-1;
  if (x>n){
    x=n;
  }

  ans=a*x/b-a*(x/b);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3636
def main():
    n, m = map(int, input().split())
    ans = [None] * n

    for i in range(m):
        s, c = map(int, input().split())
        # 桁がnより大きい
        if s > n:
            return - 1
        # 同じ桁に異なる数
        if ans[s - 1] is not None and ans[s - 1] != c:
            return -1
        ans[s - 1] = c

    if n > 1 and ans[0] == 0:
        return -1

    if n == 1 and m == 0:
        return 0

    if ans[0] is None:
        ans[0] = 1

    for i in range(n):
        if ans[i] is None:
            ans[i] = 0

    return ''.join(map(str, ans))


if __name__ == '__main__':
    print(main())


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

int main(){
  int N;
  cin >> N;
  vector<int> card(N);
  
  for (int i=0; i<N; i++)
    cin >> card.at(i);  
  
  //for(int i=0;i<N;i++){cout << card.at(i)<<",";}cout<<endl;
  sort(card.begin(), card.end());
  //for(int i=0;i<N;i++){cout << card.at(i)<<",";}cout<<endl;
  
  int A=0;
  int B=0;
  
  if(N%2==0){
    for(int i=1;i<N;i+=2){
      A += card.at(i);
    }
    for(int i=0;i<N;i+=2){
      B += card.at(i);
    }
    
  }
 
  else{
    for(int i=0;i<N;i+=2){
      A += card.at(i);
    }
    for(int i=1;i<N;i+=2){
      B += card.at(i);
    }
  }
  
  cout << A-B << endl;
}

Measured memory_bytes: 256
def main():
    K, N = tuple([int(_x) for _x in input().split()])
    A = [int(_x) for _x in input().split()]
    maxdiff = 0
    for i in range(1, len(A)):
        maxdiff = max(maxdiff, A[i] - A[i-1])
    maxdiff = max(maxdiff, K + A[0] - A[-1])
    print(K-maxdiff)


main()


Measured memory_bytes: 31664
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<sstream>
#include<iomanip>

using namespace std;

#define INF 999999999

int main(){
	int ans, i, j, k, n, m, d, p, dis;
	int at[11];
	while(1){
		cin >> n >> m;
		if(!n) break;
		for(k=0;k<=10;k++)at[k] = 0;
		ans = 0;
		dis = 0;
		for(i=0;i<n;i++){
			cin >> d >> p;
			at[p] += d;
			dis += d;
		}
		dis -= m;
		for(j=0;j<=10&&dis>0;j++){
			if(at[j] <= dis){
				dis -= at[j];
				ans += at[j] * j;
			}
			else{
				ans += dis * j;
				dis = 0;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans ;
//map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
    int n , k ;
    cin >> n >> k ;
    cout << n - k + 1 ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}
/*
    update - o(1) - log time
*/


Measured memory_bytes: 256
//
// Created by 10034 on 2020/7/28.
//

#include <iostream>
#include <algorithm>
using namespace std;
int a[200010];
int main(){
    int n;
    cin>>n;
    long long sum=0,mn=1e9+1;
    for(int i=1,x;i<=n;++i){
        cin>>a[i];
    }
    sort(a+1,a+n+1,greater<int>());

    sum=a[1];
    int tn=n-2;
    for(int i=2;i<=n&&tn;++i){
        if(tn>=2) {
            sum += a[i] * 2;
            tn -= 2;
        }
        else {
            sum+=a[i];
            break;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3972
<?php

    fscanf(STDIN,"%d",$N);
        
    $memo = array();
    for($i=0;$i<$N;$i++){
        $memo[$i] = -1;
    }

    

    function ryuka($n,&$memo){
        if($n==1 ){
            return 1;
        }
        if($n==0){
            return 2;
        }

        if($memo[$n-1] != -1){
            return $memo[$n-1];
        }
        
        $memo[$n-1] = ryuka($n-1,$memo)+ryuka($n-2,$memo);
        return $memo[$n-1];
    }

    echo ryuka($N,$memo)."\n";

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

using namespace std;

typedef long long int64;

int main()
{
  int N;

  cin >> N;
  deque< int > deq;
  for(int i = 0; i < 3 * N; i++) {
    int A;
    cin >> A;
    deq.emplace_back(A);
  }
  sort(begin(deq), end(deq));

  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    int a = deq.back();
    deq.pop_back();
    int b = deq.back();
    deq.pop_back();
    int c = deq.front();
    deq.pop_front();
    ret += b;
  }

  cout << ret << endl;
}

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadLineLongInt();
            long re = 0;

            for (int i = 1; i <= n; i++) {
                if (i % 3 == 0 || i % 5 == 0) continue;
                re += i;
            }

            Console.WriteLine(re);
            ReadLine();
        }

        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static long ReadLineLongInt() => long.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}


Measured memory_bytes: 27468
#include <iostream>
using namespace std;
int main (){
    string s;
    cin>> s;
    if (s=="Sunny"){
        cout<<"Cloudy"<<endl;
    } else if (s=="Cloudy"){
    cout<<"Rainy"<<endl;
    } else if ( s== "Rainy") {
    cout<< "Sunny" <<endl;
    }
    }





















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

bool solve(){
    int H,W;
    cin>>H>>W;
    vector<string> a(H);
    rep(y,H) cin>>a[y];
    int alpha[26]={};
    rep(y,H)rep(x,W) {
        alpha[a[y][x]-'a']++;
    }
    int set4=0,set2=0;
    rep(c,26){
        set4 += alpha[c]/4;
        set2 += ((alpha[c]%4)>=2);
    }
    set4 -= (H/2)*(W/2);
    set2 -= (W%2)*(H/2) + (H%2)*(W/2);
    if(set4<0) return false;
    set2 += set4*2;
    return set2==0;
}

int main(void){
    cout<<(solve() ? "Yes" : "No")<<endl;
    return 0;
}


Measured memory_bytes: 256
// //AUTHOR:BlackBox Inc.//
// #include<bits/stdc++.h>
// #include<unordered_map>
// #include<tr1/unordered_map>
// #define ll long long
// #define ull unsigned long long
// #define vi vector<int>
// #define vlli vector<long long int>
// #define vvi vector<vector<int>>
// #define endl "\n"
// #define vpii vector<pair<int,int>>
// #define vs vector<string>
// #define lin1(x) ll int x; x = scan();
// #define lin2(x,y) ll int x, y; x = scan(), y = scan();
// #define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
// #define pb(x) push_back(x)
// #define makep(x,y) make_pair(x,y)
// #define mx(a,b) (a)>(b)?(a):(b)
// #define mn(a,b) (a)<(b)?(a):(b)
// #define fori(s,e) for(i=s;i<=e;i++)
// #define forj(s,e) for(j=s;j<=e;j++)
// #define fork(s,e) for(k=s;k<=e;k++)
// #define rep(i,s,e) for(int i=s;i<=e;i++)
// #define brep(i,s,e) for(int i=s;i>=e;i--)
// #define all(x) x.begin(),x.end()
// #define mem(x,y) memset(x,y,sizeof(x));
// #define bits1(x) __builtin_popcount(x)
// #define pi 3.14159265358979323846264338327950
// #define MOD7 1000000007
// #define MOD9 1000000009
// #define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
// using namespace std;
// using namespace std::tr1;

// int main()
// {
// #ifdef RAHUL
//     freopen("input.txt","r",stdin);
// #endif

// int rahul;
// cin>>rahul;

// cout<<pow(2, int(log(rahul)/log(2)))<<endl;

// return 0;
// }
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif

char c; 
cin>>c;

if(c=='A'){
	cout<<"T"<<endl;
}

if(c=='T'){
	cout<<"A"<<endl;
}

if(c=='C'){
	cout<<"G"<<endl;
}
else if(c=='G'){
	cout<<"C"<<endl;
}


return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main(){
    int a,p;
    cin >> a >> p;
    cout << (a*3+p)/2 << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

		int N = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[N];
		for(int i=0; i<N; i++)
			a[i] = sc.nextInt();
		
		int[] min = a.clone();
		
		long ans = Long.MAX_VALUE;
		for(int i=0; i<N; i++) {
			long temp = (long)x*i;
			
			for(int j=0; j<N; j++) {
				min[j] = Math.min(min[j], a[(j-i+N)%N]);
				temp += min[j];
			}
			
			ans = Math.min(ans, temp);
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 13624
#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--)
 
int main() {
  int n, t;
  cin >> n >> t;
  int sum = 0;
  int ray = 0;
  rep ( i, n ) {
    int shower;
    cin >> shower;
    if ( (shower - ray) >= t ) sum += t;
    else sum += (shower - ray);
    ray = shower;
  }
  sum += t;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, a[200005];
long long p[200005];

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = n; i >= 1; i--) {
        p[i] = (p[i + 1] + a[i]) % mod;
    }

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = (ans + a[i] * p[i + 1]) % mod;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 5912
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const auto INF = (ll)1e9;
using v = vector<ll>;
using p = pair<ll,ll>;
using m = map<ll,ll>;
using vv = vector<v>;
int gcd(int a,int b){
    return a==0? b :gcd(a,a%b);
}


int main(){
    string o,e;
    cin >> o >> e;
    for (size_t i = 0; i < min(o.size(),e.size()); i++)
    {
        cout << o[i]<<e[i];
    }
    
  	if(o.size()>e.size()){
    	cout << o[o.size()-1];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    int ans = 3*n*n;

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

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>

using namespace std;

typedef pair<char,char> P;
typedef pair<int,int> II;

void dfs(bool *used,const vector<P>& vec,int p)
{
  if(used[p])
    return;
  used[p] = true;
  char next = vec[p].second;
  for(int i=0;i<vec.size();i++)
    {
      if(!used[i] && vec[i].first == next)
	dfs(used,vec,i);
    }

}

int main()
{
  int n;
  while(cin >> n,n)
    {
      vector<P> vec;
      map<char,II> Euler;
      for(int i=0;i<n;i++)
	{
	  string word;
	  cin >> word;
	  vec.push_back(P(word[0],word[word.size()-1]));
	  Euler[word[0]].first++;
	  Euler[word[word.size()-1]].second++;
	}

      bool used[n];
      for(int i=0;i<n;i++)
	used[i] = false;

      dfs(used,vec,0);

      bool f = true;
      for(int i=0;i<n;i++)
	if(!used[i])
	  f = false;

      for(map<char,II>::iterator it = Euler.begin();it != Euler.end();it++)
	if((*it).second.first != (*it).second.second)
	  f = false;

      f?cout << "OK" << endl:cout << "NG" << endl;

    }
  return 0;
}

Measured memory_bytes: 1716
n, m, l = map(int, input().split()) # n = 3, c = 2, l = 3

a_matrix = [list(map(int, input().split())) for row in range(n)] # [[1, 2], [0, 3], [4, 5]]
b_matrix = [list(map(int, input().split())) for row in range(m)] # [[1, 2, 1], [0, 3, 2]]

result_matrix = [[0 for x in range(l)] for y in range(n)] # [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(n):
	for j in range(l):
		for k in range(m):
			result_matrix[i][j] += a_matrix[i][k] * b_matrix[k][j]

for i in range(n):
	print(' '.join(map(str, result_matrix[i])))

Measured memory_bytes: 8896
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            min = Math.min(min, a);
            max = Math.max(max, a);
        }
        System.out.println(max - min);
    }
}

Measured memory_bytes: 22740
import math
import fractions
gcd = math.gcd if hasattr(math, "gcd") else fractions.gcd

A, B = map(int, input().split())

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

g = gcd(A, B)

print(len(set(factorize(g)))+1)

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

int main() {
  int64_t A, B, C;
  cin >> A >> B >> C;
  if(A == 0){
    cout << B/C+1 << endl;
  }
  else {
    cout << B/C - (A-1)/C << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include "cmath"
#include <cstdlib>

using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    vector<ll> dp(N+1);
    for (int i = 0; i < N+1; i++) {
        if (i == 0 || i == 1) {
            dp[i] = 0;
        } else {
            ll tmp = 1000000000000;
            for (int j = 1; j <= min(i-1, K); j++) {
                if (tmp > dp[i - j] + abs(h[i-1] - h[i - j - 1])) {
                    tmp = dp[i - j] + abs(h[i-1] - h[i - j - 1]);
                }
            }
            dp[i] = tmp;
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;
int N;
int main(){
	cin>>N;
	vi A;
	A.pb(0);
	ll cost=0;
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		A.pb(a);
	}
	A.pb(0);
	for(int i=0;i<N+1;i++){
		cost=cost+abs(A[i+1]-A[i]);
	}
	//cout<<cost<<endl;
	for(int i=1;i<=N;i++){
		ll hoge=abs(A[i+1]-A[i])+abs(A[i]-A[i-1]);
		ll fuga=abs(A[i+1]-A[i-1]);
		cout<<cost+fuga-hoge<<endl;
	}
}

Measured memory_bytes: 1784
#include <stdio.h>
#include <string.h>

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

/* 文字から数値に変換 */
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

/* 文字列から数値へ変換して key を生成する */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); /* 文字列を数値に変換 */
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); /* 文字列を数値に変換 */
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

/////////////////////////////////////////////////////////////
class FastFourierTransform {
 public:
  using C = complex<double>;

  void dft(vector<C> &f, int m, int v) {
    if (m == 1) return;

    vector<C> f0(m / 2), f1(m / 2);
    for (int i = 0; i < m / 2; ++i) f0[i] = f[2 * i];
    for (int i = 0; i < m / 2; ++i) f1[i] = f[2 * i + 1];

    dft(f0, m / 2, v);
    dft(f1, m / 2, v);

    C z(cos(M_PI / (m / 2)), sin(M_PI / (m / 2)) * v);
    C pow = 1;

    for (int i = 0; i < m; ++i) {
      f[i] = f0[i % (m / 2)] + f1[i % (m / 2)] * pow;
      pow *= z;
    }
  }

  vector<ll> multiply(vector<C> &g, vector<C> &h) {
    int t = (int)(g.size() + h.size()) + 1;

    int n = 1;
    while (n <= t) n <<= 1;

    g.resize(n);
    h.resize(n);

    dft(g, n, 1);
    dft(h, n, 1);

    vector<C> gh(n);
    for (int i = 0; i < n; ++i) gh[i] = g[i] * h[i];
    dft(gh, n, -1);

    for (int i = 0; i < n; ++i) gh[i] /= C(n, 0);

    vector<ll> ret(n);

    for (int i = 0; i < n; ++i) ret[i] = llround(gh[i].real());

    return ret;
  }

  vector<ll> multiply(vector<int> &g, vector<int> &h) {
    vector<C> gc(g.size());
    vector<C> hc(h.size());

    for (int i = 0; i < g.size(); ++i) {
      gc[i].real(g[i]);
    }

    for (int i = 0; i < h.size(); ++i) {
      hc[i].real(h[i]);
    }

    return multiply(gc, hc);
  }
};
/////////////////////////////////////////////////////////////

const int MAX_N = (int)(1e5 + 5);
const int MAX_A = (int)(1e5 + 5);

int n;
ll m;
ll a[MAX_N];

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &m);

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

  vector<int> g(MAX_A);

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

  vector<int> h(g);

  FastFourierTransform fft;

  vector<ll> gh = fft.multiply(g, h);

  ll cur = 0LL;

  ll ans = 0LL;

  for (int i = gh.size() - 1; i >= 0; --i) {
    if (cur == m) break;

    if (gh[i] == 0LL) continue;

    ll take = min(m - cur, gh[i]);

    cur += take;

    ans += take * (ll)(i);
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 24384
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	int n;
	int a[3];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1]) printf("YES\n");
	else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 2504
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int M = scan.nextInt();
        int ans = 0;
        int p = N+M;
        switch(p){
            case 3:ans=3;break;
            case 5:ans=1;break;
            case 4:ans=2;break;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21588
while True:
    a, op, b = input().split()       
    a =int(a)                   
    b = int(b)                   

    if op=='?': 
        break
    else:    
        if op=='+':
            print(a+b)
        elif op=='-':
            print(a-b)
        elif op=='*':
            print(a*b)
        elif op=='/':
            print(a//b)


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

using namespace std;

#define MAX_V 100
#define MAX_E 10000

int par[MAX_V],rank[MAX_V];
int V,E;

struct edge{ int u,v,cost; };
edge es[MAX_E];

bool comp(const edge &e1, const edge &e2){
  return e1.cost < e2.cost;
}

void init(int n){
  for(int i = 0 ; i < n ; i++){
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);

  if(x == y){
    return;
  }

  if(rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x] == rank[y]){
      rank[x]++;
    } 
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}

int kruskal(){
  sort(es, es + E, comp);

  init(V);
  int res = 0;

  for(int i = 0 ; i < E ; i++){
    edge e = es[i];

    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res += e.cost;
    }
  }
  return res;
}

int main(){
  int c;

  cin >> V;
  for(int i = 0 ; i < V ; i++){
    for(int j = 0 ; j < V ; j++){
      cin >> c;

      if(c == -1){
	continue;
      }

      edge e = {i,j,c};
      es[E++] = e;
    }
  }

  cout << kruskal() << endl; 

  return 0;
}

Measured memory_bytes: 1268
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] T = new int[N+1];
    int sum = 0;
    for (int i = 1; i <= N; i++) {
      T[i] = sc.nextInt();
      sum += T[i];
    }
    int M = sc.nextInt();
    for (int i = 0; i < M; i++) {
      int P = sc.nextInt();
      int X = sc.nextInt();
      System.out.println(sum - T[P] + X);
    }
  }
}

Measured memory_bytes: 23252
a,b=map(int,input().split())
num=list(input())
non=False

for (i,c) in zip(range(0,a+b+1),num):
  if c=="-":
    if i==a:
      continue
    else:
      non=True
      break
  elif i==a:
    non=True
    break
    
if non:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
import java.util.Scanner;

class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder(sc.next());
        int n = sc.nextInt();
        int a, b;
        for(int i = 0; i<n; i++)
        {
            String str = sc.next();
            a = sc.nextInt();
            b = sc.nextInt();
            if(str.compareTo("replace")==0) sb = sb.replace(a, b+1, sc.next());
            else if (str.compareTo("reverse")==0)
            {
                if(a==0 && b==sb.length()) sb = sb.reverse();
                else
                {    while(true)
                    {
                        if(a>=b)break;
                        else
                        {
                            char temp = sb.charAt(a);
                            sb = sb.deleteCharAt(a);
                            sb = sb.insert(a, sb.charAt(b-1));//b-1 since, 1 char is deleted. 
                            sb = sb.deleteCharAt(b);
                            sb = sb.insert(b, temp);
                            a++; b--;
                        }
                    }
                } 
            }
            else
            {
                char arr[] = sb.toString().toCharArray();
                for(int c=a; c<=b;c++) 
                {
                    System.out.print(arr[c]);
                }
                System.out.println();
            }
          
        }
    }
}


Measured memory_bytes: 32200
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc051.contest.atcoder.jp/tasks/abc051_d>
問題文============================================================
 自己ループと二重辺を含まない N 頂点 M 辺の重み付き無向連結グラフが与えられます。
 i(1≦i≦M) 番目の辺は頂点 ai と頂点 bi を距離 ci で結びます。
 ここで、自己ループは ai=bi(1≦i≦M) となる辺のことを表します。
 また、二重辺は (ai,bi)=(aj,bj) または (ai,bi)=(bj,aj)(1≦i<j≦M) となる辺のことを表します。
 連結グラフは、どの異なる 2 頂点間にも経路が存在するグラフのことを表します。
 どの異なる 2 頂点間の、どの最短経路にも含まれない辺の数を求めてください。
=================================================================

解説=============================================================

================================================================
*/
struct edge{
    int u,v,c;
    edge(){}
    edge(int u,int v,int c):u(u),v(v),c(c){}
};
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N,vector<int>(N,INF));
    vector<edge> E;
    for(int i = 0; i < N;i++) G[i][i] = 0;
    for(int i = 0; i < M;i++){
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        G[a][b] = G[b][a] = c;
        E.push_back(edge(a,b,c));
    }
    for(int i = 0; i < N;i++) for(int j = 0; j < N;j++) for(int k = 0; k < N;k++)
        G[j][k] = min(G[j][k],G[j][i] + G[i][k]);
    
    int ans = 0;
    for(int i = 0; i < M;i++){
        bool f = false;
        for(int j = 0; j < N;j++){
            for(int k = 0; k < N;k++){
                if(j == k) continue;
                if(G[j][k] == G[j][E[i].u] + E[i].c + G[E[i].v][k]) f = true;
            }
        }
        if(!f) ans++;
    }
    cout << ans << endl;
	return 0;
}


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

int main(int argc, char **argv) {
  char a = '\0', b = '\0';
  int acnt, bcnt;
  string S;
  cin >> S;

  for (int i = 0; i < 4; i++) {
    if (a == S[i] || b == S[i]) {
      if (a == S[i])
        acnt++;
      if (b == S[i])
        bcnt++;
    } else {
      if (a == '\0') {
        a = S[i];
        acnt = 1;
      }
      else if (b == '\0') {
        b = S[i];
        bcnt = 1;
      }
    }
  }

  if (acnt == 2 && bcnt == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

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

    long long red = 0, green = 0, blue = 0;
    for (auto color : s) {
        if (color == 'R') red++;
        if (color == 'G') green++;
        if (color == 'B') blue++;
    }

    // 1つ目の条件を満たす組の数はr*g*bで求められる
    long long condition1 = red * green * blue;

    // ２つ目の条件を満たさないものを求め、それを1つ目の中から引く
    // 判定を簡単にするためにr = 1; g = 2, b = 4と置き換えておく
    rep(i, n) {
        if (s[i] == 'R') s[i] = 1;
        if (s[i] == 'G') s[i] = 2;
        if (s[i] == 'B') s[i] = 4;
    }

    // j - i = k - jとなるものを調べる
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            // i番目とj番目が一致
            if (s[i] == s[j]) continue;
            // i と j を固定しているのでk = 2 j - i となる
            int k = 2 * j - i;
            // kがn以上だと組を作れない
            if (k >= n) continue;
            if (s[i] + s[j] + s[k] == 7) condition1--;
        }
    }
    cout << condition1 << endl;
}


Measured memory_bytes: 3652
from operator import itemgetter
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
if n%2==1:
  x=l[n//2][0]
  l=sorted(l,key=itemgetter(1))
  y=l[n//2][1]
  print(y-x+1)
else:
  x=(l[n//2][0]+l[(n//2)-1][0])/2
  l=sorted(l,key=itemgetter(1))
  y=(l[n//2][1]+l[(n//2)-1][1])/2
  print(int((y-x)*2)+1)

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

int main() {
    ll m, n;
    cin >> m >> n;
    if(m >= 2)m -=2;
    if(n >= 2)n -=2;
    cout << m*n << endl;
}

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

using lint = int64_t;
#define bit(n) ((lint)1 << n);
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

class IoSetup {
    public:
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
        cerr << fixed << setprecision(12);
    }
} iosetup;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n + 1);
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        cin >> l[i];
        l[i] += l[i - 1];
        if (l[i] <= x) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;cin >> n>>m;
    int a[n][m];
    int b[m];
    rep(i,n) {
        rep(j,m) {
            cin >> a[i][j];
        }
    }
    rep(i,m) {
        cin >> b[i];
    }
    rep(i,n) {
        int c = 0;
        rep(j,m) {
            c += a[i][j] * b[j];
        }
        ct(c);
    }
}


Measured memory_bytes: 3208
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, ll M, vector<ll> a, vector<ll> b, vector<ll> c) {
  vector<vector<int>> X(N, vector<int>(N, 1e9));
  REP(i,N) X[i][i] = 0;
  REP(i,M) {
    X[a[i]-1][b[i]-1] = c[i];
    X[b[i]-1][a[i]-1] = c[i];
  }
  auto Y = X;
  REP(k,N) REP(i,N) REP(j,N)
    chmin(Y[i][j], Y[i][k] + Y[k][j]);
  int res = 0;
  REP(i,N) REP(j,N)
    if (X[i][j] < 1e9 && X[i][j] > Y[i][j]) ++res;
  cout << res / 2 << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll M;
	scanf("%lld", &N);
	scanf("%lld", &M);
	vector<ll> a(M-1+1);
	vector<ll> c(M-1+1);
	vector<ll> b(M-1+1);
	for (int i = 0 ; i <= M-1 ; i++) {
	  scanf("%lld", &a[i]);
	  scanf("%lld", &b[i]);
	  scanf("%lld", &c[i]);
	}
	solve(N, M, a, b, c);
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#define BUFSIZE 1000000
int A,B,C,D;
int rem,rem2;
int cal(int c,int d){
	if(c%d==0){
		rem2=c/d;
	}else{
		rem2=(c-c%d)/d+1;
	}
	return 0;
	
}

int main(void){
	scanf("%d %d %d %d",&A,&B,&C,&D);
	cal(C,B);
	rem=rem2;
	cal(A,D);
		
	if(rem <= rem2){
		printf("Yes");
		
	}else{
		printf("No");
	}
}

Measured memory_bytes: 1736
#include<stdio.h>
#define N 101
int m[N][N],p[N];
void matrixChainOrder(int n) 
{
  int i,l,j,k,q;
  for(i=1; i<=n; i++) m[i][i]=0;
  for(l=2; l<=n; l++)
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      m[i][j]=1E+9;
      for(k=i; k<=j-1;k++){
	q = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j] =  m[i][j]>q ? q:m[i][j];
      }
    }
}

int main()
{
  int n,i,r,c;
  int min;

  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d%d",&r,&c);
    if(i==0) p[i]=r;
    p[i+1]=c;
  }
  matrixChainOrder(n);
  printf("%d\n",m[1][n]);
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i <b; i++)
using pii = pair<int,int>;
#define all(a) a.begin(), a.end()

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

pii keta(int K){
    int A = 0, B = 0;
    B = K % 10;
    while(K >= 10){
        K /= 10;
    }
    A = K;
    return make_pair(A, B);
}

int main(){
    int N; cin >> N;
    //int t = N, k = 0;
    ll ans = 0;
    /* while(t > 0){
        t /= 10;
        k++;
    } */
    map<pii,int> mp;
    rep(i, 1, N + 1){
        mp[keta(i)]++;
    }
    for(auto e: mp){
        int A = e.first.first, B = e.first.second;
        ans += mp[{B,A}] * e.second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256