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

template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long ll;
typedef unsigned int ui;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)

int main()
{
	//freopen("1.in","r",stdin);
	int x,a,b,c;
	cin>>a>>b>>c>>x;
	x/=50;
	int ans=0;
	rep(i,0,a)
	rep(j,0,b)
	{
		int y=x-10*i-2*j;
		if(y>=0&&y<=c)++ans;
	}
	cout<<ans;
}


Measured memory_bytes: 256
import collections
N,K = map(int,input().split())
dic = {}
A = []
for _ in range(N):
    t,d = map(int,input().split())
    A.append([t,d])
A.sort(key = lambda x:x[1], reverse = True)
val = 0
set_ = set()
duplicated = collections.deque([])
for t,d in A[:K]:
    val += d
    if t in set_:
        duplicated.append(d)
    else:
        set_.add(t)
now = val + len(set_)**2

nx = collections.deque(A[K:])
ans = now
c = len(set_)
while len(set_) < K and nx:
    i,j = nx.popleft()
    if i in set_:
        continue
    d = duplicated.pop()
    diff = j-d + 2*c+1
    set_.add(i)
    now += diff
    ans =max(ans,now)
    c += 1
print(ans)


Measured memory_bytes: 102916
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

const int limit = 50;
vint a[limit],b[limit];
bool graph[limit][limit];
bool visited[limit];

int main(){
  int n;
  cin >> n;
  map<int,int> count;
  rep(i,n){
    int a;
    cin >> a;
    count[a]++;
  }
  int ans = 0;
  for(auto p:count){
    auto key = p.first;
    auto value = p.second;
    if(value > 0){
      if(key < value){
        ans += value - key;
      }
      else if(key > value){
        ans += value;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4736
from sys import stdin

N, M, *A = map(int, stdin.read().split())
req = {1: 2,
       2: 5,
       3: 5,
       4: 4,
       5: 5,
       6: 6,
       7: 3,
       8: 7,
       9: 6}

B = sorted([(a, req[a]) for a in A], key=lambda x: x[0], reverse=True)
a_min, n_min = min(B, key=lambda x: x[1])
g = [(a, n-n_min) for a, n in B if a > a_min and n > n_min]
l = [(a, n-n_min) for a, n in B if a < a_min and n > n_min]
l.sort(key=lambda x: x[1], reverse=True)
C = g + l

def dp(rem, C):
    ret = None
    if rem == 0:
        ret = []
    elif rem > 0:
        for i in range(len(C)):
            a, m = C[i]
            nxt = dp(rem-m, C[i:])
            if nxt is not None:
                ret = [a] + nxt
                break
    return ret


i = 0
while True:
    quo = N // n_min - i
    rem = N % n_min + i * n_min
    lst = dp(rem, C)
    if lst is not None:
        lst = sorted(lst + [a_min] * (quo-len(lst)), reverse=True)
        print(''.join(map(str, lst)))
        break
    i += 1

Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

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
#define ll long long int

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &x:a)cin>>x;
    ll s=0;
    for(int i=1;i<n;i++){
        if(a[i]>=a[i-1]){
            continue;
        }
        else{
            s+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<s<<"\n";
    return 0;
}


Measured memory_bytes: 4044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;


int main()
{
    int n;  cin >> n;
    vector<int> v(n),p(n),q(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    for(int i = 0; i < n; i++){
        cin >> q[i];
    }
    for(int i = 0; i < n; i++){
        v[i] = i+1;
    }
    int cnt1 = 0,cnt2 = 0;
    do{
        bool all = true;
        for(int i = 0; i < n; i++){
            if(p[i] != v[i])all = false;
        }
        if(all){
            break;
        }else{
            cnt1++;
        }
    } while (next_permutation(v.begin(),v.end()));
    for(int i = 0; i < n; i++) v[i] = i+1;
    do{
        bool all = true;
        for(int i = 0; i < n; i++){
            if(q[i] != v[i])all = false;
        }
        if(all){
            break;
        }else{
            cnt2++;
        }
    } while (next_permutation(v.begin(),v.end())); 
    cout << abs(cnt1-cnt2);
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define Ms(s, n) memset(s, n, sizeof(s))
#define Rp(i,l,m) for(int i=l; i<m; ++i)
#define Rpd(i,l,m) for(int i=l; i>=m; --i)
#define Rpp(i,l,m) for(int i=l; i<=m; i++)
#define RpAll(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define All(a) (a).begin(), (a).end()
#define Fi first
#define Se second
#define Pb push_back
#define Pf push_front
#define Is insert
#define Sz(a) int((a).size())
#define ooi INT_MAX
#define ool LLONG_MAX
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
inline ll gcd(ll a,ll b) {ll r;while(b){r=a%b;a=b;b=r;}return a;}
inline ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
inline ll fpow(ll n,ll k){ll r=1; for(;k;k>>=1){if(k&1)r=r*n%MOD;n=n*n%MOD;}return r;}
const int base = 311;
const int N = 2e5 + 5;

ll n, m, k, test;
ld a[100];

void Solve(){
    cin >> n;
    for(int i = 1; i<=n; i++){
        cin >> a[i];
    }
    sort(a+1, a+n+1);
    for(int i = 2; i<=n; i++){
        a[i] = 1.0*(a[i-1] + a[i])/2.0;
    }
    cout << a[n];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    Solve();
    return 0;
}




















Measured memory_bytes: 256
#include <iostream>
#define MOD 1000000007

using namespace std;

int main()
{
    long long n;
    long long ans = 1;

    cin >> n;

    for (int i = 1; i <= n; i++) {
        ans *= i;

        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {

    new Main().run();
  }

  public void run() {

    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n;
      BigDecimal num1,num2,sum;
      n = Integer.parseInt(br.readLine());
      for (int i=0; i<n; i++) {

        num1 = new BigDecimal( br.readLine() );
        num2 = new BigDecimal( br.readLine() );

        if ( num1.precision() > 80 || num2.precision() > 80)
          System.out.println("overflow");
        else
          if( (sum = num1.add(num2)).precision() > 80 )
            System.out.println("overflow");
          else
            System.out.println(sum);
      }
    } catch (IOException e) {
      System.err.println(e);
    }
  }
}


Measured memory_bytes: 24676
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    string s;
    cin >> s;
    bool C = false;
    bool F = false;
    REP(i,s.length()){
        if(s[i] == 'C') C = true;
        else if(C && s[i] == 'F') F = true;
    }
    if(C && F) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N(0);
  cin >> N; 
  int l[N], r[N];
  
  int np(0);
  for(int i = 0; i < N; i++)
  {
   	cin >> l[i] >> r[i];
    np += (r[i] - l[i] + 1);
  }
  cout << np << endl;
}
 

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        N: usize,
        A:[usize;N-1]
    }
    let mut buka : Vec<i32>= vec![0;N];
    for a in A.iter(){
        buka[a-1] = buka[a-1]+1;
    }
    for b in buka {
        println!("{}", b);

    }


}

Measured memory_bytes: 5492
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 55

const int INF = 1e9 + 7;

int T, H, W, N;
char mp[ARRAY_MAX][ARRAY_MAX];
int p[26][4];//p[][0]:xmini,p[][1]:xmax,p[][2]:ymini,p[][3]:ymax,
bool ans;
bool used[26];


void dfs(int cnt) {

	if (ans)
	{
		return;
	}

	if (cnt == N)
	{
		//最後まで調べられた(長方形以外のものがない)
		ans = true;
		return;
	}

	//1番上にあるものから順に取り除いていく
	for (int k = 0; k < 26; k++)
	{
		if (used[k] == false)
		{
			//使わない文字なら飛ばす
			continue;
		}

		for (int i = p[k][0]; i <= p[k][1]; i++)
		{
			for (int j = p[k][2]; j <= p[k][3];j++)
			{
				//長方形になっていない場合はreturn
				if (mp[i][j] == '.')
				{
					return;
				}
				if (mp[i][j] - 'A' != k && used[mp[i][j] - 'A'] == false)
				{
					//矩形内に別の材質のものがあった場合について
					//usedがtrueであれば上に乗っかっていた場合を考えているのでここは通過するが、
					//falseの場合は上に乗っていなかった場合であるためこの矩形は長方形ではない
					
					return;
				}
			}
		}

		//以下矩形は長方形であった場合

		used[k] = false;//(ただ単に取り除いた)
		dfs(cnt + 1);
		used[k] = true;//取り除く（上に乗っていたケースと考えるので矩形内の別の材質は自身のマスと考えてよい）
	}
}


int main(){


	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> T;
	for (int i = 0; i < T; i++)
	{
		cin >> H >> W;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> mp[i][j];
			}
		}

		for (int i = 0; i < 26; i++)
		{
			p[i][0] = p[i][2] = INF;//mini
			p[i][1] = p[i][3] = 0;//maxi
		}

		N = 0;
		ans = false;
		memset(used, false, sizeof(used));

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (mp[i][j] == '.')
				{
					continue;
				}
				int index = mp[i][j] - 'A';
				p[index][0] = min(p[index][0], i);
				p[index][1] = max(p[index][1], i);
				p[index][2] = min(p[index][2], j);
				p[index][3] = max(p[index][3], j);
				if (used[index] == false) {
					N++;
					used[index] = true;//falseならこの文字を使用

				}
			}
		}
		dfs(0);

		if (ans == true)
		{
			cout << "SAFE" << endl;
		}
		else
		{
			cout << "SUSPICIOUS" << endl;
		}
	}

	return 0;
}




Measured memory_bytes: 3136
def main():
    N = int(input())
    h = [int(x) for x in input().split()]

    dp = [float('inf')] * (2 * N)

    dp[0] = 0

    for i in range(1, N):
        dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
        if i > 1:
            dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

    print(dp[N-1])


if __name__ == "__main__":
    main()


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

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

  vector< pair< int64_t, int64_t > > xy(N);
  vector< pair< int64_t, int64_t > > yx(N);
  for (int i=0;i<N; ++i) {
    int64_t xin, yin;
    cin >> xin >> yin;
    xy[i]  = make_pair( xin, yin );
  }

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

  map< pair<int64_t,int64_t> , int > m;
  
  for (int i=0; i<N-1; ++i ) {
    for (int j=i+1; j<N; ++j ) {
      int64_t xdif = xy[j].first - xy[i].first;
      int64_t ydif = xy[j].second - xy[i].second;
      if ( m.find( make_pair( xdif,ydif) ) != m.end() ) {
        m.at(make_pair( xdif,ydif)) += 1;
      } else {
        m.insert(make_pair(make_pair( xdif,ydif),1));
      }
//        cout << xdif << " " << ydif << " " << m.at(make_pair( xdif,ydif)) << endl;
    }
  }

  int cmax = 0;
  for ( auto it=m.begin(); it != m.end(); ++it ) {
    cmax = max( cmax, it->second );
//    cout << "#cmax " << cmax << endl;
  }
  
  cout << (N-cmax) << endl;
}



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

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

	int a, b, c, d, e, f;
	int water, sugar, msugar;
	int mx, my;
	double mpercent = 0, percent;
	cin >> a >> b >> c >> d >> e >> f;
	for (int i = 0; 100*a*i <= f; ++i){
		for (int j = 0; 100*b*j <= f - 100*a*i; ++j){
			water = 100*a*i + 100*b*j;
			msugar = f - water;
			for (int k = 0; c*k <= msugar; ++k){
				for (int l = 0; d*l <= msugar - c*k; ++l){
					sugar = c*k + d*l;
					if (water * e < 100 * sugar){
						continue;
					}
					percent = (double)(100*sugar)/(water+sugar);
					if (percent >= mpercent){
						mpercent = percent;
						mx = water;
						my = sugar;
					}
				}
			}
		}
	}
	cout << mx + my << " " << my << "\n";
	return 0;
}

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

int main() {
  int n; cin>>n;
  bool frag=false;
  int y = -1;
  int tmp = 0;
  while (n > 0) {
    int x = n%10;
    if (y != x) {
      y = x;
      tmp = 1;
    }
    else tmp++;
    n/= 10;
    if (tmp>=3) frag = true;
  }
  if (frag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int main() {
	int T; read(T);
	while (T--) {
		int x, y; read(x), read(y);
		if (x == y) {
			printf("%d\n", x + y - 2);
			continue;
		}
		if (x > y) swap(x, y);
		int ans = x - 1;
		int l = 0, r = y;
		while (l < r) {
			int mid = (l + r + 1) / 2;
			if (1ll * mid * mid < 1ll * x * y) l = mid;
			else r = mid - 1;
		}
		ans += (1ll * x * y - 1) / (l + 1) - x;
		ans += l;
		writeln(ans);
	}
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin>>n;
    set<string> st;
    for(int i = 0;i < n;++i) {
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;
    return 0;
}


Measured memory_bytes: 19120
#include <stdio.h>
void swap(int*, int*);

int main(void)
{
    int x, y;

    while (1) {
        scanf("%d %d", &x, &y);
        if (x == 0 && y == 0) {
            break;
        }
        if (x > y) {
            swap(&x, &y);
        }
        printf("%d %d\n", x, y);
    }
    return 0;
}

void swap(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

struct UnionFind {
    // 根は大きさの負
    // それ以外は親を持つ
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    int root (int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    bool unite (int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool same_root (int x, int y) {
        return root(x) == root(y);
    }
    int size (int x) {
        return -data[root(x)];
    }
};

int main() {
    int n, m; cin >> n >> m;
    
    UnionFind tree(n);
    rep(i,m) {
        int a, b; cin >> a >> b;
        tree.unite(a, b);
    }

    int ans = 0;
    rep(i,n) {
        chmax(ans, tree.size(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4016
#include <set>
#include <vector>
#include <iostream>
using namespace std;
vector<vector<int> > G;
int calc(int pos, int pre) {
	int ans = 0;
	for (int i : G[pos]) {
		if (i != pre) {
			ans ^= calc(i, pos) + 1;
		}
	}
	return ans;
}
int main() {
	int N;
	cin >> N;
	G.resize(N);
	for (int i = 0; i < N - 1; ++i) {
		int x, y;
		cin >> x >> y; --x, --y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	int ans = calc(0, -1);
	cout << (ans ? "Alice" : "Bob") << endl;
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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;}
using namespace std;

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

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <array>
using namespace std;

int main(){
	int n;
	cin >> n;
	array<array<int,13>,4> v;
	string str;
	int num;
	for(int i = 0; i < 13; i++) {
		v[0][i] = 0;
		v[1][i] = 0;
		v[2][i] = 0;
		v[3][i] = 0;
	}
	for(int i = 0; i < n; i++){			
		cin >> str >> num;
		if("S" == str) v[0][num-1] = 1;
		if("H" == str) v[1][num-1] = 1;
		if("C" == str) v[2][num-1] = 1;
		if("D" == str) v[3][num-1] = 1;
	}
	for(int j = 0; j < 13; j++){
		if(v[0][j] != 1){
			cout << "S " << j+1 << endl;
		}
	}
	for(int j = 0; j < 13; j++){
		if(v[1][j] != 1){
			cout << "H " << j+1 << endl;
		}
	}
	for(int j = 0; j < 13; j++){
		if(v[2][j] != 1){
			cout << "C " << j+1 << endl;
		}
	}
	for(int j = 0; j < 13; j++){
		if(v[3][j] != 1){
			cout << "D " << j+1 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp setprecision(12)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define ll long long
#define double long double
#define MAX (int)(5*pow(10,3) + 10)
#define pb(a) push_back(a)
// #define cout out
// #define cin in
ll inf = pow(10,18);
ll INF = inf;
ll modulo = pow(10,9) + 7;
double eps = 1e-10;
ifstream in;
ofstream out;


void deal(){
	map<string,ll> all;
	ll n;
	cin>>n;
	fori(n){
		string a;
		cin>>a;
		sort(a.begin(), a.end());
		all[a]++;
	}
	ll s = 0;
	for(auto& el: all)
		s+=(el.ss*(el.ss-1))/2;
	cout<<s;
}
 
int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}

Measured memory_bytes: 11264
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	if (N == 3||N==5 || N == 7)cout << "YES\n";
	else cout << "NO\n";
	return 0;
}


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

int main() {
  int N;
  int M;

  cin >> N;
  int T[N];
  for (int i = 0; i < N; i++) cin >> T[i];
  cin >> M;
  int P[M];
  int X[M];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  int sum = 0;
  for (int i = 0; i < N; i++) sum += T[i];

  for (int i = 0; i < M; i++){
    cout << sum - T[ P[i] - 1] + X[i] <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,point,win[10],low[10];
char str[10];
while(cin>>n&&n!=0){
for(int i=0;i<n;i++){
win[i]=0;low[i]=0;
cin>>str[i];
for(int j=1;j<n;j++){
cin>>point;
if(point==0)win[i]++;
else if(point==1)low[i]++;
}
}
for(int i=0;i<n;i++){
point=0;
for(int j=1;j<n;j++)if(win[point]<win[j]||win[point]==win[j]&&low[point]>low[j])point=j;
cout<<str[point]<<endl;
win[point]=-1;
low[point]=11;
}
}

}

Measured memory_bytes: 1152
//-----------
var log = console.log;
if(typeof process != "undefined"){
	var p = process.stdin;
	p.resume();
	p.setEncoding('utf8');
	p.on('data',function(line){
		before(line);
	});
}
function before(line){
	var lines = line.split("\n");
	lines = lines.filter(function(e){return (e !== "");});
	main(lines);
}

//-----------
function main(lines){
	var ls = lines.map(function(e){return Number(e);});
	while(ls.length > 1){
		var tpl = ls.shift();
		var arr = ls.slice(0,tpl);
		ls = ls.slice(tpl);
		var mid = arr.indexOf(Math.min.apply(this,arr));
		arr.splice(mid,1);
		var Mid = arr.indexOf(Math.max.apply(this,arr));
		arr.splice(Mid,1);
		var sum = arr.reduce(function(p,c,i,a){return p+c;});
		log(Math.floor(sum/arr.length));
	}
}

Measured memory_bytes: 16104
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()
a = l()
ma = Max
co = 0
for i in range(n):
    if a[i] < ma:
        ma = a[i]
        co += 1
print(co)






Measured memory_bytes: 23948
import java.io.BufferedInputStream
import java.io.InputStream
import java.util.StringTokenizer

const val INF = 100000000
fun solve(N: Int, A: Int, B: Int, C: Int, l: IntArray) {
    fun dfs(a: Int, b: Int, c: Int, cur: Int, merge: Int): Int = when (cur) {
        N -> {
            if (a <= 0 || b <= 0 || c <= 0) INF
            else listOf(A - a, B - b, C - c).sumBy { Math.abs(it) } + (merge - 3) * 10
        }
        else -> listOf(
            dfs(a, b, c, cur + 1, merge),
            dfs(a + l[cur], b, c, cur + 1, merge + 1),
            dfs(a, b + l[cur], c, cur + 1, merge + 1),
            dfs(a, b, c + l[cur], cur + 1, merge + 1)
        ).min()!!
    }
    println(dfs(0, 0, 0, 0, 0))
    return
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val A = sc.next().toInt()
    val B = sc.next().toInt()
    val C = sc.next().toInt()
    val l = IntArray(N)
    for (i in 0 until N) {
        l[i] = sc.next().toInt()
    }
    solve(N, A, B, C, l)
}


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

int main() {
	long long D, N;
	cin >> D >> N;
	/*if (D == 2 && N == 100) {
		cout << 1010000 << endl;
		return 0;
	}*/
	if (N < 100) {
		cout << N * pow(100, D) << endl;
	}
	else {
		//cout << 101 * pow(100, D) << endl;
        printf("%d\n",int(101 * pow(100, D)));
	}
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{

    long long a, b;
    cin >> a >> b;
    if(a >= b / 2)
    {
        cout << b / 2 << endl;
    }
    else
    {
        long long d = 0, g = b / 2, s;
        while (d <= g)
        {
            s = (d + g) / 2;
            if(a + s < (b - 2 * s) / 2)
            {
                d = s + 1;
            }
            else if(a + s > (b - 2 * s) / 2)
            {
                g = s - 1;
            }
            else
            {
                d = s;
                g = -1;
            }
        }
        cout << b / 2 - d << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 3333
LL n,mod,s[N][N],c[N][N];
LL mul(LL a,LL b,LL p){
	LL res=0;
	for (;b;b>>=1,a=(a+a)%p){
		if (b&1) res=(res+a)%p;
	}
	return res;
}
inline LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while (ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while (ch>='0' && ch<='9'){
        x=x*10+ch-'0';ch=getchar();
    }
    return x*f;
}
LL fastpow(LL a,LL b,LL p){
	LL res=1;
	for (;b;b>>=1,a=mul(a,a,p)){
		if (b&1) res=mul(res,a,p);
	}
	return res;
}
int main(){
	n=read(),mod=read();
	for (int i=1;i<=n;++i){
		c[i][0]=c[i][i]=1;
		for (int j=1;j<i;++j){
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
		}
	}
	for (int i=0;i<=n;++i){
		s[i][0]=1;
		for (int j=1;j<=i;++j){
			s[i][j]=(s[i-1][j-1]+s[i-1][j]*(j+1)%mod)%mod;
		}
	}
	LL ans=0;
	for (int i=0;i<=n;++i){
		LL k=c[n][i];
		if (i&1) k=(mod-k)%mod;
		LL x=fastpow(2,n-i,mod-1);
		x=fastpow(2,x,mod);
		LL tmp=fastpow(2,n-i,mod);
		LL cnt=0,y=1;
		for (int j=0;j<=i;++j){
			cnt=(cnt+(s[i][j]*y%mod))%mod;
			y=tmp*y%mod;
		}
		ans=(ans+(k*cnt%mod*x%mod))%mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 158336
n, m = map(int, input().split())
h = [0]+list(map(int, input().split()))
ans = [0]+[1]*n
for i in range(m):
    a, b = map(int, input().split())
    if h[a]>=h[b]:
        ans[b] = 0
    if h[b]>=h[a]:
        ans[a] = 0
print(sum(ans))

Measured memory_bytes: 20100
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    r = int(input())
    if r < 1200:
        print("ABC")
    elif r < 2800:
        print("ARC")
    else:
        print("AGC")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9500
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
string ans[200050];
string s1[200050];
map<string,int>vis;
bool cmp(string a,string b)
{
    return a<b;
}
int t;
int main()
{
    vis.clear();
    scanf("%d",&t);
    int maxx=-1;
    for(int i=1;i<=t;i++)
    {
        cin>>s1[i];
        vis[s1[i]]++;
        maxx=max(vis[s1[i]],maxx);
    }
    int cnt=0;
    for(int i=1;i<=t;i++)
    {
        if(vis[s1[i]]==maxx)
        {
            ans[cnt++]=s1[i];
            vis[s1[i]]=0;
        }
    }
    sort(ans,ans+cnt,cmp);
    for(int i=0;i<cnt;i++)
        cout<<ans[i]<<endl;
}


Measured memory_bytes: 28288
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int N;

int main(void)
{
	scanf("%d", &N);

	if (N < 1200)
		printf("ABC\n");
	else if (N < 2800)
		printf("ARC\n");
	else
		printf("AGC\n");

	return 0;
}

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

int main() {

    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    sort(a, a+3);

    if(a[0] == a[1] && a[1] == a[2]){
        cout << "No" << endl;
    }
    else if(a[0] != a[1] && a[1] != a[2]){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()

    # def tousa(a, d, x):
    #     return x * (2 * a + (x - 1) * d) // 2

    # 約数を列挙　n=10^12までいける
    ans = 0
    for i in range(1, n + 1):
        ans += (n // i) * (2 * i + (n // i - 1) * i) // 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 72688
#include<bits/stdc++.h>
using namespace std;
void func(int n);
int ans[3] = {0};
int flg,sum;
string s;
int main(void){
	cin >> s;
	flg = 0;
	func(0);
	return 0;
}

void func(int n){
	//printf("n = %dsum = %dflg=%d\n",n,sum,flg);
	int i;
	if(flg == 0){
		if(n == 3){
			sum = s[0] - '0';
			for(i = 0; i < 3; i++){
				if(ans[i] == 1)	sum += s[i + 1] - '0';
				else			sum -= s[i + 1] - '0';
			}
			if(sum == 7){
				for(i = 0; i < 3; i++)	cout << s[i] << ((ans[i])?'+':'-');
				cout << s[3] << "=7" << endl;
				flg = 1;
			}
		}
		else{
			func(n + 1);
			ans[n] = 1;
			func(n + 1);
			ans[n] = 0;
		}
	}
}

Measured memory_bytes: 3624
#include<stdio.h>
int func();

int main(){
    int dice[100][6];
    int n;
    int i,j;
    int flag=1;
    
    scanf("%d", &n);
    for(i=0;i<n;i++)for(j=0;j<6;j++)scanf("%d", &dice[i][j]);

    for(i=1;i<n;i++){
        flag = func(dice[0],dice[i]);
        if(flag){
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");
    return 0;
}

int func(int a_dice[], int b_dice[]){
    int surface[24][3]={{1,2,3},{2,3,1},{3,1,2},
                        {1,3,5},{3,5,1},{5,1,3},
                        {1,5,4},{5,4,1},{4,1,5},
                        {1,4,2},{4,2,1},{2,1,4},
                        {6,2,4},{2,4,6},{4,6,2},
                        {6,4,5},{4,5,6},{5,6,4},
                        {6,5,3},{5,3,6},{3,6,5},
                        {6,3,2},{3,2,6},{2,6,3}};
    int i;

    for(i=0;i<24;i++){
        if((a_dice[surface[i][0]-1]==b_dice[0]) && (a_dice[surface[i][1]-1]==b_dice[1])  && (a_dice[surface[i][2]-1]==b_dice[2])){
            if((a_dice[6-surface[i][0]]==b_dice[5]) && (a_dice[6-surface[i][1]]==b_dice[4])  && (a_dice[6-surface[i][2]]==b_dice[3])){
                return 1;
            }
        }
    }
    return 0;
}


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

int main(){
  int n,m;
  cin >>n >>m;
  vector<ll> h(n);
  rep(i,n) cin >>h[i];
  int num[n] = {0};
  rep(i,m){
    int a,b;
    cin >>a >>b;
    a--; b--;
    if(h[a]<=h[b]) num[a]--;
    if(h[a]>=h[b]) num[b]--;
  }
  int cnt = 0;
  rep(i,n){
    if(num[i]==0) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 4576
a, b, c = map(str, input().split())

if a == '5' and b == '5':
    if c == '7':
        print('YES')
        exit(0)

if b == '5' and c == '5':
    if a == '7':
        print('YES')
        exit(0)

if a == '5' and c == '5':
    if b == '7':
        print('YES')
        exit(0)

print('NO')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
             cout << std::setprecision(15) ;
         int h,w,k;
         cin>>h>>w>>k;
         string s[h];
         for(int i=0;i<h;i++)cin>>s[i];
         int dp[h][w];
        dp[0][0]=s[0][0]-'0';
        for(int i=1;i<w;i++)dp[0][i]=s[0][i]-'0';
        for(int i=1;i<h;i++){
                dp[i][0]=dp[i-1][0]+(s[i][0]-'0');
                for(int j=1;j<w;j++){
                        dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+(s[i][j]-'0');
                }
        }
        int p,q,d[h],dd[h]={},ans=h*w+1;bool t=true,tt;
        for(int i=(1<<(h-1));i<(1<<h);i++){
                for(int j=0;j<h;j++)d[j]=0;
                p=1;q=0;t=true;
                for(int r=0;r<w;r++){
                        tt=false;
               for(int j=0;j<h;j++){
                       if(s[j][r]=='1')q++;
                       if(i&(1<<j)){
                               if(q>k)t=false;
                               dd[j]=q;
                               q=0;
                       }

               }
               for(int j=0;j<h;j++){

                       if(d[j]+dd[j]>k)tt=true;
               }
               if(tt){
                       p++;
                       for(int j=0;j<h;j++){
                               d[j]=dd[j];
                               dd[j]=0;
                       }
               }else{
                       for(int j=0;j<h;j++){
                               d[j]+=dd[j];
                               dd[j]=0;
                       }
               }
              
               //  cerr<<p<<' ';
                }
              //  cerr<<endl;
               
                if(t){
                        q=0;
                        for(int j=0;j<h;j++)if(i&(1<<j))q++;
                        ans=min(q+p-2,ans);
                }


        }
        cout<<ans;

         
}

        


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

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

    rep(i, t.size()){
        if(t.at(i)=='?'){
            cout << "D";
        }else{
            cout << t.at(i);
        }
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,g;
vector<ll> prime,fact,a;
set<ll> ans;

void prime_list(ll n,vector<ll>& p){
	ll visited[300010]={};
	reg(i,2,n){
		if(visited[i]==0){
			p.push_back(i);
			reg(j,2,n){
				if(j*i>n)break;
				visited[i*j]=1;
			}
		}
	}
}
void factoring(ll n,vector<ll>& v,vector<ll>& p){
	rep(i,p.size()){
		while(n%p[i]==0){
			n/=p[i];
			v.push_back(p[i]);
		}
	}
	if(n>1)v.push_back(n);
}

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

bool division(vector<ll> v,ll p){//ここは変更するのでコピーにしないといけない
	bool ok=true;
	rep(i,v.size())v[i]%=p;
	rep(i,v.size()){
		if(i+(p-1)>=v.size()-1)break;//最後は定数なので変えられない
		ll t=v[i];
		v[i]-=t;
		v[i+(p-1)]+=t;
	}
	rep(i,v.size())if(v[i]%p!=0)ok=false;
	return ok;
}

void init(){
	cin>>n;
	reg(i,0,n){
		ll b;
		cin>>b;
		a.push_back(b);
	}
	g=abs(a[0]);
	reg(i,1,n)g=gcd(g,abs(a[i]));
	prime_list(100010,prime);
	factoring(g,fact,prime);
	rep(i,fact.size())ans.insert(fact[i]);
	cerr<<"初期化終了"<<endl;
}

int main(void){
	init();
	rep(i,prime.size()){
		if(prime[i]>n)break;
		if(division(a,prime[i]))ans.insert(prime[i]);
	}
	for(auto itr=ans.begin();itr!=ans.end();itr++){
		cout<<*itr<<endl;
	}
	return 0;
}

Measured memory_bytes: 2816
#include<stdio.h>
int main()
{
    int a[4][3][10]={0};
    int b,f,r,v,n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        a[b-1][f-1][r-1]+=v;
    }
    for(b=0;b<4;b++){
        for(f=0;f<3;f++){
            for(r=0;r<10;r++){
                printf(" %d",a[b][f][r]);
            }
            printf("\n");
        }
        if(b!=3){
            printf("####################\n");
        }
    }
    return 0;
}



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


//  Created by liszt on 2019/07/31.
#include<bits/stdc++.h>
using namespace std;

int main(){
    //input
    int n,omax=0,emax=0,om,em,i,a,b;
    vector<int> o(100001,0);
    vector<int> e(100001,0);
    cin>>n;
    
    for(i=0;i<n/2;i++){
        cin>>a>>b;
        o[b]++; e[a]++;
        if(o[b]>omax){omax=o[b];om=b;}
        if(e[a]>emax){emax=e[a];em=a;}
    }
    
    sort(o.rbegin(),o.rend());
    sort(e.rbegin(),e.rend());

    if(om!=em){
        cout<<n-o[0]-e[0]<<endl;
    }else{
        cout<<min(n-o[0]-e[1],n-o[1]-e[0])<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
//https://atcoder.jp/contests/dp/tasks/dp_m
//O(n*K*K) solution

#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX 1e9+7
#define lim 1e5
using namespace std;

const lld mod=MAX;


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

	int n,k;
	cin>>n>>k;

	std::vector<int> v(n);

	for(int i=1;i<=n;i++)
		cin>>v[i];

	int dp[k+1];

	memset(dp,0,sizeof(dp));

	
	dp[0]=1;

	for(int i=1;i<=n;i++)
	{
		std::vector<int> prefsum(k+1);

		prefsum[0]=dp[0];

		for(int t=1;t<=k;t++)
		{
			prefsum[t] = (prefsum[t-1]+dp[t])%mod;
		}


		for(int j=1;j<=k;j++)
		{
			//dp[i][j] = (dp[i][j]%mod + dp[i-1][j-t]%mod)%mod;

			if(j-v[i]>0)
			{
				dp[j] = ((prefsum[j]-prefsum[j-v[i]-1])+mod)%mod;
			}

			else
				dp[j] = prefsum[j]%mod;
		}
	}


	cout<<dp[k]%mod<<endl;

}
//https://atcoder.jp/contests/dp/submissions/13269695

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
using namespace std;
const int maxn = 1e5+10;
int b[maxn];
bool dp[maxn];
int main() {
    int n , k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i <= k; i++) {
        bool a[n];
        for (int j = 0; j < n; j++) {
            if(i-b[j] < 0 || dp[i-b[j]]){
                a[j] = 1;
            }else{
                a[j] = 0;
            }
        }
        bool ans = a[0];
        for (int j = 0; j < n; j++) {
            ans = (ans && a[j]);
        }
        
        dp[i] = !ans;
    }
    
    if( dp[k]){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
    return 0;
    
}


Measured memory_bytes: 384
from collections import deque


def upd(a, b, v):
    global N
    dp[a][b] = max(dp[a][b], v)
    dp[b][a] = max(dp[b][a], v)
    dp[N][a] = max(dp[N][a], v)
    dp[N][b] = max(dp[N][b], v)
    dp[a][N] = max(dp[a][N], v)
    dp[b][N] = max(dp[b][N], v)
    dp[N][N] = max(dp[N][N], v)


N = int(input())
A = list(map(lambda x: int(x) - 1, input().split()))

INF = 1 << 32
dp = [[-INF] * (N + 1) for _ in range(N + 1)]
upd(A[0], A[1], 0)
base = 0
q = deque()

for i in range(2, 3 * N - 1, 3):
    x, y, z = A[i], A[i + 1], A[i + 2]
    if x == y == z:  # x, y, z 3文字すべて等しいとき
        base += 1
    else:
        for _ in range(3):
            # a, b, x, y, z のうち, b, y, z を消すとき
            for k in range(N):
                v = dp[k][N]
                if y == z:
                    v = max(v, dp[k][y] + 1)
                q.append((k, x, v))
            # a, b, x, y, z のうち, a, b, z を消すとき
            v = max(dp[z][z] + 1, dp[N][N])
            q.append((x, y, v))
            # x, y, z をローテート
            x, y, z = z, x, y
        while q:
            a, b, v = q.popleft()
            upd(a, b, v)

l = A[-1]
ans = max(dp[N][N], dp[l][l] + 1)
print(ans + base)


Measured memory_bytes: 228936
p = []
q = []
while(1):
    a,b = [int(i) for i in input().split(",")]
    if a == 0 and b == 0:
        break
    p.append(a)
    q.append(b)
q_ = sorted(list(set(q)))
q_rank = [i+1 for i in range(len(q_))[::-1]]
q_dic = dict(zip(q_,q_rank))
rank = dict(zip(p,[q_dic[i] for i in q]))

while(1):
    try:
        a = int(input())
        print(rank[a])
    except EOFError:
        break


Measured memory_bytes: 5600
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}

int main() {
	string S;
	cin >> S;
	if (S.length() == 2)
		cout << S << endl;
	else {
		reverse(S.begin(), S.end());
		cout << S << endl;
	}
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  //vector<int> b(n);
  int ans=0;
  int tmp;
  vector<int> c(n-1);
  for(int i=0; i<n; i++){cin >> a.at(i);}
  for(int i=0; i<n; i++){cin >> tmp;
                        ans += tmp;}
  for(int i=0; i<n-1; i++){cin >> c.at(i);}
  for(int i=0; i<n-1; i++){
    if(a.at(i)+1==a.at(i+1)){ans += c.at(a.at(i)-1);}
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)



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

	ll sum = 0;
	if (N % 2 == 0) {
		for (ll i = 5; i <= N; i = i * 5) {
			sum += N / (i * 2LL);
		}
	}
	cout << sum << endl;
	

}

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

using namespace std;

int main() {

	int N;
	cin >> N;

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

	unsigned long long int r = 0, l = 0;
	for (int i = 0; i < N; i++)
		r += A[i];

	unsigned long long int sa = 2100000000;

	for (int i = 0; i < N; i++) {
		l += A[i];
		r -= A[i];

		sa = min(sa, max(r,l)-min(r,l));
	}

	cout << sa << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
#include<bits/stdc++.h>
#define maxn 1000000007

using namespace std;

bool f(pair<long long,int>a, pair<long long, int>b){ //desending order of the pair of B and C
  if(a.second > b.second)
    return 1;
  else
      return 0;
}

bool F(long long a, long long b){ //ascending order of A
  if(a<b)
    return 1;
  else
    return 0;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N,M;
  long long C;
  int B;
  cin>>N>>M;
  vector<long long>arr(N);
  for(int i=0;i<N;i++) cin>>arr[i];
  vector< pair<long long,int> >v(M);
  for(int i=0;i<M;i++){
    cin>>B>>C;
    v.push_back(make_pair(B,C));
  }
  sort(arr.begin(),arr.end(),F);
  sort(v.begin(),v.end(),f);
  int it=0;
  for(int i=0;i<M;i++){
    if(v[i].second>arr[it]){
      while(v[i].first>0 && it<N && v[i].second>arr[it]){
        arr[it]=v[i].second;
        it++;
        v[i].first--;
      }
    }
  }
  long long ans=0;
  for(int i=0;i<N;i++)
    ans+=arr[i];
  cout<<ans;  
  return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	char x,y;
	cin >> x >> y;
	if(x<y) cout << '<' << endl;
	else if(x==y) cout << '=' << endl;
	else cout << '>' << endl;
//////////////////////////////////////////////
}


Measured memory_bytes: 256