akhauriyash/Code-Regression huggingface dataset:
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}

int N, col[100005];
Vec< Vec< int > > adj;

bool pathRec(int v, int p, Vec< int >& path) {
	if (v == N - 1) return true;
	
	for (int u : adj[v]) {
		if (u == p) continue;
		
		if (pathRec(u, v, path)) {
			path.push_back(v);
			return true;
		}
	}
	
	return false;
}

void colRec(int v, int p, int c) {
	if (col[v] != -1) return;
	col[v] = c;
	for (int u : adj[v]) {
		if (u == p) continue;
		colRec(u, v, c);
	}
}

void solve() {
	memset(col, -1, sizeof(col));
	col[0] = 1;
	col[N - 1] = 0;
	
	Vec< int > path;
	pathRec(0, -1, path);
	reverse(path.begin(), path.end());
	assert(path[0] == 0);
	
	int m = path.size();
	int lft = 1, rgt = m - 1;
	while (lft <= rgt) {
		col[path[rgt]] = 0;
		col[path[lft]] = 1;
		++lft;
		--rgt;
	}
	
	for_(v,0,N) {
		if (col[v] != -1) {
			for (int u : adj[v]) colRec(u, v, col[v]);
		}
	}
	
	int F = accumulate(col, col + N, int());
	int S = N - F;
	
	puts(F > S ? "Fennec" : "Snuke");
}


int main() {
	cin >> N;
	adj.assign(N, Vec< int >());

	for_(i,0,N-1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	solve();
}

Measured memory_bytes: 13052
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
const int A = 1e9+7;
int dp[110000];
void test_case() {
	int n, a,b,c; ; cin >> n;
	cin >> a >> b >> c;
	int x ,y,z;x=a;y=b;z=c;
	int x1,y1,z1;
	for (int i = 1;i<n;++i){
		cin >> a >> b >> c;
		x1 = a + max(y,z);
		y1 = b + max(z,x);
		z1 = c + max(x,y);
		x = x1;y=y1;z=z1;
	}
	cout << max({x,y,z});
	
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int T=1;
	//cin >> T;
	while(T--) {
		test_case(); 
		
	}
}


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

int main(){
  int d,n;
  cin >> d >> n;
  int a[150];
  int aaa;
  if(d == 0) aaa=1;
  if(d == 1) aaa=100;
  if(d == 2) aaa=10000;
  for(int i=1;i<=101;i++){
    a[i]=aaa*i;
  }
  if(n!=100)
  cout << a[n] << endl;
  else
  cout << a[n+1] << endl;
  return 0;
}

Measured memory_bytes: 256
function main(input){
  input = input.split('\n');


  if(input[0].indexOf('RRR') != -1){
    console.log('3');
  } else if (input[0].indexOf('RR') != -1){
    console.log('2');
  } else if(input[0].indexOf('R') != -1){
    console.log('1');
  }else{
    console.log('0');
  }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());


Measured memory_bytes: 29648
N = int(input())
A = [-int(input()) for i in range(N)]

#weakly increase
def LIS(L):
    INF = float('inf')
    DP = [INF]*(N+1)

    def bisect(v):
        if v<DP[0]:
            return 0
        l = 0
        r = N
        while r-l>1:
            if v<DP[(l+r)//2]:
            #if v<=DP[(l+r)//2]:
                r = (l+r)//2
            else:
                l = (l+r)//2
        return r
    
    for v in L:
        DP[bisect(v)] = v
    return DP

DP = LIS(A)
count = 0
for i in range(N):
    if DP[i]<10**10:
        count+=1
    else:
        break
print(count)

Measured memory_bytes: 56152
#include <bits/stdc++.h>
using namespace std;
long INF=10000000000;

//関数
long prefol(long k){//kは753数か下一桁が0
    if(k%10==0) return k-0+3;
    if(k%10==3) return k-3+5;
    if(k%10==5) return k-5+7;
    if(k%10==7){
        long copk=k;
        long count=0;
        while(copk%10==7){
            copk/=10;
            count++;
        }
        
        long result=prefol(copk);
        for(int i=0;i<count;i++){
            result*=10;
            result+=3;
        }
        return result;
    }
}

bool val(long x){//非負整数が753数か返す。
    long th=0,fi=0,se=0;
    while(x>0){
        if(x%10==3)th++;
        else if (x%10==5)fi++;
        else if(x%10==7)se++;
        else return false;
        
        x/=10;
    }
    return (th*fi*se>0);
}

void bfs(long k,long N){
    
}

long fol(long x){
    x=prefol(x);
    while(!val(x)){
        x=prefol(x);
    }
    return x;
}



//main関数
int main() {
    
    
    //入力
    long N;
    cin>>N;
    
    //計算
    long ans=0;
    long x=357;
    while(N>=x){
        ans++;
        x=fol(x);
    }

    
 
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[100],ans;
  double d,q=114514,da[100],p=0,dn;
  cin>>n;
  dn=n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    da[i]=a[i];
    p+=da[i];
  }
  d=p/dn;
  for(int i=0;i<n;i++){
    if(abs(da[i]-d)<q){
      ans=i;
      q=abs(da[i]-d);
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;

#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




ll const mod=998244353;

ll f[200001];

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

ll mod_inv(ll x,ll mod){
    return mod_pow(x, mod - 2);
}

ll nCr(ll n, ll r)
{
    return (f[n]*((mod_inv(f[r], mod) * mod_inv(f[n-r], mod)) % mod)) % mod;
}


int main(int argv, char* argc[])
{
    FASTIO




    	f[0] = 1;
        for(ll i = 1 ; i <= 200000 ; i++)
		f[i] = (f[i-1]*i)%mod;



    ll n,m,k,sum=0;
    cin>>n>>m>>k;

    for(ll i=0;i<=k;++i)
    {
        ll a = 1;


        a*=m;a%=mod;
        a*=mod_pow(m-1,n-i-1);a%=mod;
        a*=nCr(n-1,n-i-1);a%=mod;


        sum+=a;
        sum%=mod;


    }
    cout<<sum;


    return 0;
}



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

int n, cnt = 0, now = 0;
vector<int> h;

int main() {
  cin >> n;
  h.resize(n);
  for(int i = 0; i < n; ++i) cin >> h[i];
  for(int i = 0; i < n; ++i)
    if(h[i] >= now) {
      ++cnt;
      now = h[i];
    }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int ans = 0;
        
        String[] sArray = new String[s.length()];
        for(int i = 0; i < s.length(); i++){
            String s2 = String.valueOf(s.charAt(i));
            sArray[i] = s2;
        }
        for(int i = 0; i < n-2; i++){
            if(sArray[i].equals("A")){
                if(sArray[i+1].equals("B")){
                    if(sArray[i+2].equals("C")){
                        ans++;
                    }else{
                        
                    }
                }else{
                    
                }
            }else{
                
            }
            
        }
        System.out.print(ans);
    }
           
}

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

typedef pair<int,int> pii;
#define fi first
#define se second

int m;
vector<pii> v;

int gcd(int a, int b) {
	return a % b ? gcd(b, a % b) : b;
}

int solve(int stat, vector<pii> & ktmk) {
	int res = 0;
	if(stat == (1 << m)-1 || true) {
		vector<pii> vv(ktmk.begin(), ktmk.end());
		sort(vv.begin(), vv.end());
		vv.push_back(pii(-1,-1));
		int t = 1;
		for(int i = 1; i <= vv.size(); i++) {
			if(vv[i] == vv[i-1]) {
				t++;
			}
			else {
				res += t * (t-1) / 2;
				t = 1;
			}
		}
		/*
		for(int i = 0; i < vv.size(); i++) {
			cout << vv[i].fi << "," << vv[i].se << " ";
		} cout << endl;
		cout << res << endl;
		// */
		//return res;
	}

	for(int i = 0; i < m; i++) {
		if((stat & (1<<i)) == 0) {
			for(int j = i+1; j < m; j++) {
				if((stat & (1<<j)) == 0) {
					pii a(v[i].fi - v[j].fi, v[i].se - v[j].se);
					if(a.se == 0) {
						a.fi = 0;
					}
					else {
						int d = gcd(a.fi, a.se);
						a.fi /= d; a.se /= d;
						if(a.se < 0) {
							a.fi *= -1; a.se *= -1;
						}
					}
					ktmk.push_back(a);
					res = max(res,solve(stat | (1 << i) | (1 << j), ktmk));
					ktmk.pop_back();
				}
			}
			break;
		}
	}
	return res;
}

int main() {
	cin >> m;
	v.resize(m);
	for(int i = 0; i < m; i++) {
		cin >> v[i].fi >> v[i].se;
	}
	vector<pii> ktmk;
	cout << solve(0,ktmk) << endl;
}

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

int main(){ string a, b; int ans = 0;
    cin >> a >> b;
    for (int i=0; i<a.length(); i++){
        if(a[i] != b[i]){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3920
#include <iostream>
using namespace std;
int main(void){
    int a=0;
    string s;
    while(cin >> s){
        if(a!=0){
            cout << " ";
        }
        a++;
        for(int i=0;i<s.size();i++){
            char c=s[i];
            if('A'<= c && c <= 'Z'){
                c=c+ 32;
            }
            else if('a'<= c && c <= 'z'){
                c=c- 32;
            }
            cout << c;
        }
         
    }
    cout << endl;
}


Measured memory_bytes: 3128
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
vector<bool> used(100,false);

void dfs(int now, int u, int v, vector<vector<int> > &G){
    used[now]=true;
    for(auto to:G[now]){
        if(!used[to] && !((u==now && v==to) || (u==to && v==now))) dfs(to,u,v,G);
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m),b(m);
    vector<vector<int> > G(n);
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        a[i]--; b[i]--;
        G[a[i]].push_back(b[i]); G[b[i]].push_back(a[i]);
    }
    int ans=0;
    for(int i=0;i<m;i++){
        int u=a[i];
        int v=b[i];
        for(int x=0;x<n;x++) used[x]=false;

        dfs(0,u,v,G);

        bool f=true;
        for(int x=0;x<n;x++) if(!used[x]) f=false;
        if(!f) ans++;
        //cout<<ans<<" ";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int cnt;
void insertionSort(int *A,int n,int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g]=A[j];
      j-=g;
      cnt++;
    }
    A[j+g]=v;
  }
}
void shellSort(int *A,int n){
  cnt=0;
  int r=1;
  vector<int> G;
  while(r<=n){
    G.push_back(r);
    r*=2;
  }
  int m=G.size();
  reverse(G.begin(),G.end());
  cout<<m<<endl;
  for(int i=0;i<m;i++) cout<<G[i]<<" \n"[i==m-1];
  for(int i=0;i<m;i++) insertionSort(A,n,G[i]);
  cout<<cnt<<endl;
}
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  shellSort(A,n);
  for(int k=0;k<n;k++) cout<<A[k]<<endl;
  return 0;
}

Measured memory_bytes: 6960
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    a = set(map(int, input().split()))
    b = set(map(int, input().split()))
    
    mod = pow(10, 9) + 7
    
    ans = 1
    field = 0
    already_a = 0
    already_b = 0
    for i in range(n*m, 0, -1):
        if i in a:
            if i in b:
                already_a += 1
                already_b += 1
                field += already_a*already_b - (already_a-1)*(already_b-1)
            else:
                already_a += 1
                field += already_a*already_b - (already_a-1)*already_b
                ans *= already_b
        else:
            if i in b:
                already_b += 1
                field += already_a*already_b - already_a*(already_b-1)
                ans *= already_a
            else:
                ans *= field
        
        ans %= mod
        field -= 1
        
    print(ans)
    
    
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 9256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll cnt[10000002];

void seive(int n)
{
    for(int i=2;i<=n;i++)
    {
        if(cnt[i]==0)
        {
            cnt[i]=1;
            for(int j=i+i;j<=n;j+=i)cnt[j]+=(cnt[j/i]+1);
        }
    }
}

int main()
{
    int n,i;
    ll ans=0;
    cin>>n;
    seive(n);
    for(i=1;i<=n;i++)ans+=(i*(cnt[i]+1));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 81720
#include <stdio.h>

int main(void)
{
	int x, y;
	int num;
	
	while (scanf("%d %d", &x, &y) != EOF){
		num = 0;
		x += y;
		while (x){
			x /= 10;
			num++;
		}
		
		printf("%d\n", num);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

template<class T>bool chmax(T &a, const T &b) {
   if (a < b) {
      a = b;
      return 1;
   }
   return 0;
}
template<class T>bool chmin(T &a, const T &b) {
   if (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const ll kInf = 1e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
   int n;
   cin >> n;
   vector<int> a(n+1);
   vector<int> b(n);
   REP(i, n+1) {
      cin >> a[i];
   }
   ll cnt = 0;
   REP(i, n) {
      cin >> b[i];
      if (b[i] >= a[i]) {
         b[i] -= a[i];
         cnt += a[i];
      } else {
         cnt += b[i];
         b[i] = 0;
      }
      if (a[i + 1] >= b[i]) {
         cnt += b[i];
         a[i + 1] -= b[i];
      } else {
         cnt += a[i + 1];
         a[i + 1] = 0;
      }
   }
   cout << cnt << endl;
   return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, x[60], y[60];
map<pair<int, int>, int > mp;
vector<int> vec[3000];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	if (n == 1) {
		cout << 1 << E;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			pair<int, int> tmp;
			tmp.fi = y[i] - y[j];
			tmp.se = x[i] - x[j];
			if (tmp.fi * 1LL * tmp.se > 0) {
				tmp.fi = abs(tmp.fi);
				tmp.se = abs(tmp.se);
			}
			else if (tmp.fi * 1LL * tmp.se < 0) {
				if (tmp.fi < 0) {
					tmp.fi = -tmp.fi;
					tmp.se = -tmp.se;
				}
			}
			else {
				if (tmp.fi) tmp.fi = abs(tmp.fi);
				if (tmp.se) tmp.se = abs(tmp.se);
			}
			mp[tmp]++;
		}
	}
	int ans = 100;
	for (auto e : mp) {
		ans = min(ans, n - e.se);
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,w;
    cin>>n>>w;
    vector<pair<long long,long long >>arr;
    arr.push_back(make_pair(0LL,0LL));
    for(long long int i=1;i<=n;i++)
    {
        long long a,b;
        cin>>a>>b;
        arr.push_back(make_pair(a,b));
    }
    long long dp[n+1][w+1];
    for(long long int i=0;i<=n;i++)
    {
        for(long long int j=0;j<=w;j++)
        {
            if(i==0 || j==0)
            dp[i][j]=0;
            else if(arr[i].first<=j)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-arr[i].first]+arr[i].second);
            }
            else
            dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w];
}


Measured memory_bytes: 79232
from heapq import heappop, heappush

T = int(input())
ans = []
for _ in range(T):
    N, A, B, C, D = map(int, input().split())

    Q = [(0, N)]
    # already processed
    S = set()
    an = D * N
    while Q:
        cost, num = heappop(Q)
        if num in S:
            continue
        an = min(an, cost + num * D)
        if num == 1:
            break
        S.add(num)

        q, r = divmod(num, 2)
        if r < 2:
            heappush(Q, (cost + A + r * D, q))
        if r > 0:
            heappush(Q, (cost + A + (2 - r) * D, q + 1))

        q, r = divmod(num, 3)
        if r < 2:
            heappush(Q, (cost + B + r * D, q))
        if r > 0:
            heappush(Q, (cost + B + (3 - r) * D, q + 1))

        q, r = divmod(num, 5)
        if r < 3:
            heappush(Q, (cost + C + r * D, q))
        if r > 0:
            heappush(Q, (cost + C + (5 - r) * D, q + 1))
    ans.append(an)

print(*ans, sep="\n")


Measured memory_bytes: 86936
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    for c in v:
        if c % 2 == 0:
            if not (c % 3 == 0 or c % 5 == 0):
                print('DENIED')
                return
    print('APPROVED')
if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<iostream>
#include<map>
using namespace std;
int a[4];
map<int,int>mp;
int main()
{
	string str;
	int n,m,s,c,maxn=-1,minn=4;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&s,&c);
		mp[s]++;
		maxn=max(maxn,s);
		minn=min(minn,s);
		if(mp[s]>1&&c!=a[s])
		{
			printf("-1\n");
			return 0;
		}
		a[s]=c;		
	}
	if(mp[1]==0&&n!=1)
	{
		a[1]=1;
	} 
	if(mp[1]>0&&a[1]==0&&n!=1)
	{
		printf("-1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)printf("%d",a[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000

//??????????????¢??????????????¨debug()??????????????????
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int A[2],ans;
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

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

void solve(){
	// if(A[1] < A[0]){
	// 	int i = A[1];
	// 	A[1] = A[0];
	// 	A[0] = i;
	// }
	// while(A[1] % A[0]){
	// 	int i = A[1] % A[0];
	// 	A[1] = A[0];
	// 	A[0] = i;
	// }
	ans = gcd(A[0],A[1]);
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	for (int i = 0; i < 2; ++i)
	{
		cin >> A[i];
	}
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <algorithm>

#define MAX_DP  100005
int dp[MAX_DP];

inline int abs( int n ){
    return (n>=0)? n:-n;
}

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> H(N);
    for( auto &h: H ){
        std::cin >> h;
    }

    if( N == 2 )
    {
        std::cout << abs(H[1]-H[0]) << std::endl;
        return 0;
    }

    // 0-origin
    dp[0] = 0;
    dp[1] = abs( H[0]-H[1] );
    
    for( int i = 2; i < N; i++ ){
        dp[i] = std::min( dp[i-2]+abs( H[i-2]-H[i] ), abs( dp[i-1]+abs(H[i-1]-H[i]) ) );
    }

    std::cout << dp[N-1] << std::endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 void push(int);
int pop();
 int top ,stack[1000];
int main(){
  int a,b;
  top = 0;
  char s[100];
  while(scanf(" %s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
    }else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }else{
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
  return 0;
}


void push(int x){
  top++;
  stack[top] = x;
}

int pop(){
  top--;
  return stack[top + 1];
	}



Measured memory_bytes: 2108
#include<iostream>
using namespace std;
unsigned long long n[88];
int main()
{
	n[0]=2;
	n[1]=1;
	for(int i=2;i<=86;i++)
	{
		n[i]=n[i-1]+n[i-2];
	}
	int j;
	cin>>j;
	cout<<n[j]<<endl;
	return 0;
}
 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		/*
		int[][] ans = new int[10001][10001];
		for (int j = 1; j < 10001; j++) {
			ans[1][j] = 0;
		}
		for (int i = 2; i < 10001; i++) {
			for (int j = 1; j < 10001; j++) {
				ans[i][j] = (ans[i - 1][j] + j) % i;
			}
		}
		*/

		while (true) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int m = sc.nextInt();
			if ((n | k | m) == 0) {
				break;
			}

			int[] ans = new int[n];
			ans[1] = 0;
			for (int i = 2; i < n; i++) {
				ans[i] = (ans[i - 1] + k) % i;
			}
			System.out.println((ans[n - 1] + m) % n + 1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

typedef long long ll;
const int MAX_N = 100000;

int main () {
	int N;
	ll a[MAX_N + 1];

	std::cin >> N;
	for(int i = 0; i < N; ++i) {
		std::cin >> a[i];
	}
	std::sort(a, a + N);
	a[N] = -1;

	int cnt = 0, ans = 0;
	ll x = a[0];
	for (int i = 0; i <= N; i++) {
		if(a[i] == x) ++cnt;
		else {
			if(cnt < x) ans += cnt;
			else ans += cnt - x;
			cnt = 1;
			x = a[i];
		}
	}

	std::cout << ans << std::endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int a, b;
	cin >> a >> b;
	char c[10];
	cin >> c;
	if(c[a] != '-') cout << "No" <<endl;
	else {
		char num[11] = "0123456789";
		int flg = 1;
		for(int i = 0; i < a; i++){
			int flgg = 0;
			for(int j = 0; j <= 9; j++){
				if(c[i] == num[j]){
					flgg = 1;
					break;
				}
			}
			if(flgg == 0){
				flg = 0;
				break;
			}
		}
		for(int i = a + 1; i <= a + b; i++){
			int flgg = 0;
			for(int j = 0; j <= 9; j++){
				if(c[i] == num[j]){
					flgg = 1;
					break;
				}
			}
			if(flgg == 0){
				flg = 0;
				break;
			}
		}
		if(flg == 0) cout << "No" <<endl;
		else  cout << "Yes" <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	int c[13];
	int a,b;
	REP(i,13){
		if(i==0){
			c[i]=13;
		}
		else{
			c[i]=i-1;
		}
	}
	cin >> a >> b;
	if(c[a-1]==c[b-1]){
		cout << "Draw" << endl;
	}
	else{
		if(c[a-1]<c[b-1]){
			cout << "Bob" << endl;
		}
		else{
			cout << "Alice" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 256
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

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

using Matrix = vector< vector<int> >;

bool d(Matrix &mat, int K) {
    int H = mat.size(), W = mat[0].size();
    int ma = -1 , mi = INF;
    rep(i,0,H) rep(j,0,W) {
        chmax(ma, mat[i][j]);
        chmin(mi, mat[i][j]);
    }

    int idx = -1;
    rep(i,0,H) {
        int tmp = -1;
        rep(j,idx,W) if(mi + K < mat[i][j]) chmax(tmp, j);
        rep(j,0,max(idx,tmp) + 1) if(ma - K > mat[i][j]) return false;
        idx = max(idx, tmp);
    }
    return true;
}

int solve(Matrix &mat) {
    int lb = 0, ub = INF;
    while(ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if(d(mat, mid)) ub = mid;
        else lb = mid;
    }
    return ub;
}

Matrix rotate(Matrix mat) {
    int H = mat.size(), W = mat[0].size();
    Matrix ret(W, vector<int>(H));

    rep(i,0,H) rep(j,0,W) {
        ret[j][H-i-1] = mat[i][j];
    }
    return ret;
}

signed main() {
    int H, W; cin >> H >> W;
    Matrix mat(H, vector<int>(W));
    rep(i,0,H) rep(j,0,W) cin >> mat[i][j];

    int ans = INF;
    rep(i,0,4) {
        chmin(ans, solve(mat));
        mat = rotate(mat);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 96880
#include <bits/stdc++.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
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; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


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

    long long a, b;
    while (cin >> a >> b) {
        if (a == 1 || b == 1) cout << 1 << endl;
        else cout << (a * b + 1) / 2 << endl;
    }
}


















Measured memory_bytes: 256
from heapq import heappush as hpush
from heapq import heappop as hpop

class Descending_HeapQueue:
    def __init__(self, hq=[]):
        self.hq = []
        for i in hq:
            self.push(i)
    def push(self, n):
        hpush(self.hq, -n)
    def pop(self):
        return -hpop(self.hq)
    def __len__(self):
        return len(self.hq)

def main():
    N, M = map(int, input().split())
    AB = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
    ans = 0
    dhq = Descending_HeapQueue()
    pointer = 0
    for m in range(1, M+1):
        while (pointer < N) and (AB[pointer][0] <= m):
            dhq.push(AB[pointer][1])
            pointer += 1
        if len(dhq) > 0:
            ans += dhq.pop()
    print(ans)
main()

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> C(N-1), S(N-1), F(N-1);
	REP(i, N-1) cin >> C[i] >> S[i] >> F[i];

	REP(i, N){
		ll now = 0;
		for(int j=i;j<N-1;j++){
			ll dep;
			if(S[j]>=now){
				dep = S[j];
			}else{
				if(now%F[j]==0) dep = now;
				else dep = ((now/F[j])+1)*F[j];
			}
			now = dep + C[j];
		}
		cout << now << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll A,B,C;
    cin >> A >> B >> C;
    if(A % 2 == 1 && B % 2 == 1 && C % 2 == 1){
        cout << min(A * B,min(B * C,A * C)) << endl;
    }else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m=1,a,b,c,d,x;
int main()
{
  for(cin>>x,i=2;i<x;i++)for(j=2;pow(i,j)<=x;j++)m=max(m,int(pow(i,j)));
  cout<<m;
}

Measured memory_bytes: 256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int a, b; cin >> a >> b;
	set<int> test = {1, 2, 3};
	test.erase(a); test.erase(b);
	println(*test.begin());
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }


ll N, K;
vector<int> adj[101];

struct El{int a, b; };
vector<El> ret;
int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> N >> K;
    ll possible_max = (N-2) * (N-1) / 2;
    if(K > possible_max) { cout << -1 << endl; return 0; }
    
    for(int i = 2; i <= N; i++)
    {
        ret.push_back(El{1, i});
    }
    
    for(int i = 2; i <= N; i++)
    {
        for(int j = i + 1; j <= N; j++)
        {
            if(possible_max > K )
            {
                possible_max -= 1;
                ret.push_back(El{i, j});
            }
        }
    }
    cout << ret.size() << endl;
    for(auto v : ret)
    {
        cout << v.a << " " << v.b << endl;
    }
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define reverse(s) reverse(s.begin(),s.end())


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

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

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

    int x(0),ans(0);
    rep(i,n){
        if(s[i]=='I'){
            x += 1;
            ans = max(ans,x);
        }
        if(s[i]=='D'){
            x -= 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3576
/*Hey, What's up?*/

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<long long>v[100];
map<pair<long long,long long> ,long long>mp;
long long xx=0,vis[100],q;
void solve(int p){
    if(p==q){xx++;return;}
    if(vis[p])return;
    vis[p]=1;
    for(int i=0;i<v[p].size();i++){
        solve(v[p][i]);
    }
}
int main()
{
    fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p;
    cin>>n>>m;
    for(i=0; i<m; i++)
    {
        cin>>a>>b;
        v[b].push_back(a);
        v[a].push_back(b);
        mp[{a,b}]=1;
        mp[{b,a}]=1;
    }
    f=0;
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(mp[{i,j}]){
                memset(vis,0,sizeof(vis));
                q=j;xx=0;
                solve(i);
                if(xx==1){
                    f++;
                }
            }
        }
    }
    cout<<f<<'\n';
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

string s;
int id;

int exp();
int term();
int fact();

int exp()
{
	int r = term();
	while(true)
	{
		char c = s[id++];
		if(c == '+')r += term();
		else if(c == '-')r -= term();
		else break;
	}
	return r;
}

int term()
{
	int r = fact();
	while(true)
	{
		char c = s[id++];
		if(c=='*') r*=fact();
		else if(c=='/')r/=fact();
		else break;
	}
	id--;
	return r;
}

int fact()
{
	char c = s[id++];
	if(c=='(')return exp();
	if(c=='-')
	{
		return -fact();
	}
	if(c=='+')
	{
		return fact();
	}
	int x = c-'0';
	while(true)
	{
		c = s[id++];
		if('0' <= c && c <= '9')
		{
			x *= 10;
			x += c-'0';
		}
		else break;
	}
	id--;
	return x;
}

void solve()
{
	int N;
	scanf("%d\n", &N);
	while(N--)
	{
		getline(cin, s);
		id = 0;
		cout << exp() << endl;
	}
}

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

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

int main() {
	string s;
	cin >> s;
	bool hantei = true;
	int c_num = 0;

	if (s[0] != 'A') { 
		hantei = false; 
	}

	for (int i = 2; i < s.size() - 1; i++) {
		if (s[i] == 'C') {
			c_num++;
		}
	}
	if (c_num != 1) {
		hantei = false;
	}

	for (int i = 1; i < s.size(); i++) {
		if (!(s[i] >= 'a'&&s[i] <= 'z')) {
			if (s[i] != 'C') {
				hantei = false;
			}
		}
	}
	if (hantei) {
		cout << "AC";
	}
	else {
		cout << "WA";
	}
}


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

signed main() {
#if 0
  long long A;
  double B;
  cin >> A >> B;
  long long BB = (long long)(B*100);
  long long ans = A*BB / 100LL;
  cout << ans << endl;
#else
  long double A,B;
  cin >> A >> B;
  cout << (long long)floor(A*B) << endl;
#endif
}


Measured memory_bytes: 3732
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

from itertools import combinations
li2 = list(combinations(li,2))

point = 0
for i in range(len(li2)):
    point += (li2[i][0] * li2[i][1])

print(point)

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

using namespace std;

#define DEBUG(x, end) cout << #x << ":" << x << end
#define DEBUG1(x, i, end) cout << #x << "[" << i << "]:" << x[i] << end
#define DEBUG2(x, i, j, end) cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << end
#define DEBUG3(x, i, j, k, end) cout << #x << "[" << i << "][" << j << "][" << k << "]:" << x[i][j][k] << end
#define INLINE(i, a, b) (((i) >= (a)) && ((i) < (b)))
#define INRANGE(i, a, b) (((i) >= (a)) && ((i) <= (b)))
#define REP(i, a, b) for (int i = (a); i < (b); i++)

const int MAXN = 5005;
int N, K;
int card[MAXN];
int sum[MAXN];
int dp[MAXN];

void dsp() {
	REP(i, 0, N + 1) {
		DEBUG1(card, i, '\t');
		DEBUG1(dp, i, '\n');
	}
}

int main() {
	cin >> N >> K;
	REP(i, 1, N + 1) {
		cin >> card[i];
	}
	sort(card + 1, card + N + 1);
	int l = 1, r = N, m;
	while (l <= r) {
		m = (l + r) >> 1;
//		printf("%d %d %d\n", l, m, r);
		if (card[m] >= K) {
			r = m - 1;
			continue;
		}
		memset(dp, 0, sizeof dp);
		REP(i, 1, N + 1) {
			REP(j, 0, i) {
				if (i == m) {
					dp[i] = max(dp[i], dp[j]);
				} else if (dp[j] + card[i] < K) {
					dp[i] = max(dp[i], dp[j] + card[i]);
				} else {
					dp[i] = max(dp[i], dp[j]);
				}
			}
		}
//		dsp();
		REP(i, 1, N + 1) {
			if (K - card[m] <= dp[i] && dp[i] < K) {
				r = m - 1;
				goto next;
			}
		}
		l = m + 1;
		next:
		continue;
	}
	cout << r << '\n';
	return 0;
} 

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

int main() {
    char input[8][9] = {};
    for (int i = 0; i < 8; i++) {
        cin >> input[i];
    }
    for (int i = 0; i < 3; i++) {
        cout << (i + 1) * 90 << endl;
        char output[8][9] = {};
        for (int y = 0; y < 8; y++) {
            for (int x = 0; x < 8; x++) {
                output[y][x] = input[7 - x][y];
            }
        }
        for (int j = 0; j < 8; j++) {
            cout << output[j] << endl;
        }
        for (int y = 0; y < 8; y++) {
            for (int x = 0; x < 8; x++) {
                input[y][x] = output[y][x];
            }
        }
    }
}

Measured memory_bytes: 0
import numpy as np
n = int(input())
a = list(map(int, input().split()))
count = np.zeros(10**6 + 1)
for x in a:
  if count[x] > 1:
    continue
  count[::x] += 1
ans = 0
for x in a:
  if count[x] == 1:
    ans += 1
print(ans)

Measured memory_bytes: 51516
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = "";
			while ((s = Console.ReadLine()) != null)
			{
				int JOI = 0, IOI = 0;
				for (int i = 0; i <= s.Length - 3; i++)
				{
					if (s.Substring(i, 3) == "JOI")
						JOI++;
					else if (s.Substring(i, 3) == "IOI")
						IOI++;
				}
				Console.WriteLine(JOI);
				Console.WriteLine(IOI);
			}
		}
	}
}

Measured memory_bytes: 5784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    reverse(a,a+n);
    int dp[n+1];
    fill(dp,dp+n+1,INF);
    for(int i=0;i<n;i++){
        if(dp[i]<=a[i]){
            dp[i+1]=a[i];
        }else{
            int idx=upper_bound(dp,dp+n+1,a[i])-dp;
            dp[idx]=a[i];
        }
    }
    cout<<lower_bound(dp,dp+n+1,INF)-dp<<endl;
}

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

#define MAX_W 100
#define MAX_H 100

char room[MAX_W][MAX_H];
int W,H;

const int direc[4][2] = {
    {0, -1},
    {1, 0},
    {0, 1},
    {-1, 0},
};

void dfs(const int& row, const int& col, const char c);

int main() {
    while(cin>>H>>W, W > 0) {
        int step = 0;
        int col, row;
        for (row = 0; row < H; ++row) {
            for (col = 0; col < W; ++col) {
                cin >> room[row][col];
            }
        }
        for (row = 0; row < H; ++ row) {
            for(col = 0; col < W; ++ col) {
                if(room[row][col] != '!') {
                    dfs(row, col, room[row][col]);
                    ++ step;
                }
            }
        }
        cout<<step<<endl;
    }
    return 0;
}

void dfs(const int& row, const int& col, const char c) {
    room[row][col] = '!';
    for(int d = 0; d < 4; ++ d) {
        int curRow = row + direc[d][1];
        int curCol = col + direc[d][0];
        if(curRow >= 0 && curRow < H && curCol >= 0 && curCol < W && room[curRow][curCol] == c) {
            dfs(curRow, curCol, c);
        }
    }
}


Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int a[100001];
int b[100001];
LL c[100001];
typedef pair<int,LL> P;
vector<P>G[100001];
int Q,K;
LL d[100001];

void dfs(int v,LL cost){
   if(d[v]!=-1)return;
   d[v]=cost;
   REP(i,G[v].size()){
       dfs(G[v][i].first,cost+G[v][i].second);
   }
}

int main(){
    cin>>N;
    REP(i,N-1){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
        G[a[i]].push_back(P(b[i],c[i]));
        G[b[i]].push_back(P(a[i],c[i]));
    }
    cin>>Q>>K;
    REP(i,N){
        d[i]=-1;
    }
    dfs(K-1,0);
    REP(i,Q){
        int x,y;
        cin>>x>>y;x--;y--;
        cout<<d[x]+d[y]<<endl;
    }
    return(0);
}

Measured memory_bytes: 15872