akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll a, b, n;
  cin >> a >> b >> n;

  ll t = b - 1;
  if(t > n) {
    t = n;
  }
  ll ans = (a * t / b) - (a * (t / b));

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 3652
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

# 購買する全パターンを回す
most_row_price = 10**10
for i in range(2**n):
    comb = str(bin(i)[2:]).zfill(n)
    
    # 購買パターン毎の購入金額と理解度を算出する
    money_per_pattern = [0] * n # 購買パターン毎の金額の初期化
    understanding = [0] * m # 理解度の初期化
    total_money = 0 # 合計購入金額の初期化
    for j in range(n):
        
        # 購入しないケースは除外する
        if comb[j] == '0':
            continue
            
        # 購入するケースだけ、金額算出する
        money_per_pattern[j] = ca[j][0]
        
        # 当該パターンの理解度を算出する
        for k in range(m):
            understanding[k] += ca[j][k+1]           
    total_money = sum(money_per_pattern)            

    judge_flg = 'ok'
    for j in range(m):
        if understanding[j] < x:
            judge_flg = 'ng'
    
    if judge_flg == 'ok':
        most_row_price = min(total_money, most_row_price)

if most_row_price == 10**10:
    print(-1)
else:
    print(most_row_price)

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

int N, A;
int main() {
  cin >> N >> A;
  vector<int> x(N);

  rep(i, N) {
    cin >> x.at(i);
    x.at(i) -= A;
  }
  sort(x.begin(), x.end());
  ll dp[2501];
  ll dp2[2501];
  rep(i, 2501) {
    dp[i] = 0;
    dp2[i] = 0;
  }
  dp[0] = 1;
  dp2[0] = 1;
  int zero = 0;
  rep(i, N) {
    if (x.at(i) < 0) {
      for (int j=2500; j>=(-x.at(i)); j--) {
        dp[j] = dp[j] + dp[j+x.at(i)];
      }
    }
    if (x.at(i) > 0) {
      for (int j=2500; j>=x.at(i); j--) {
        dp2[j] = dp2[j] + dp2[j-x.at(i)];
      }
    }
    if (x.at(i) == 0) {
      zero++;
    }
  }

  ll ans = 0;
  for (int i=1; i<=2500; i++) {
    ans += dp[i]*dp2[i];
  }
  int tmp = zero;
  while (tmp > 0) {
    ans *= 2;
    tmp--;
  }
  ll ans2 = 1;
  while (zero > 0) {
    ans2 *= 2;
    zero--;
  }
  ans2--;
  cout << ans + ans2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int H,W,N;
  cin >> H >> W >> N;
  vector<int> A(N);
  vector<int> B(N);
  int sum = 0;
  REP(i, N){
    cin >> A[i];
    sum+=A[i];
    B[i]=sum;
  }
  
  vector<vector<int>> ans(H,vector<int> (W));
  int cnt = 0;
  REP(i,H){
    if(i%2==0){
      REP(j,W){
        if(cnt<=B[0]-1){
          ans.at(i).at(j)=1;
        }
        REP(k,N-1){
          if(cnt>B[k]-1&&cnt<=B[k+1]-1){
            ans.at(i).at(j)=k+2;
          }
        }
        cnt++;
      }
    }else{
      REPR(j,W-1){
        if(cnt<=B[0]-1){
          ans.at(i).at(j)=1;
        }
        REP(k,N-1){
          if(cnt>B[k]-1&&cnt<=B[k+1]-1){
            ans.at(i).at(j)=k+2;
          }
        }
        cnt++;
      }
    }
  }

  REP(i,H){
    REP(j,W){
      if(j!=W-1){
        cout << ans.at(i).at(j) <<" ";
      }else{
        cout << ans.at(i).at(j);
      }
    }
    cout << endl;
  }
}

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

int main() {
  string s; cin >> s;
  int N = s.size();
  bool flag;
  flag = (s[0]=='A');
  if(flag){
    int c_count = 0;
    for(int i=2;i<=N-2;i++){
      if(s[i]=='C'){
        c_count += 1;
        if(c_count>1){
          flag = false;
          break;
        }
      }
    }
    if(flag){
      flag = (c_count==1);
    }
    if(flag){
      for(int i=1;i<N;i++){
        char c = s[i];
        if( !( (c>='a'&&c<='z') || c=='C' )){
          flag = false;
          break;
        }
      }
    }
  }
  if(flag){
    cout << "AC" << endl;
  }else{
    cout << "WA" << endl;
  }
}

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

int main(){
	int n;
  	int tochu=0;
  	long c=1;
  	cin >> n;
  	vector<int> a(n);
  	for(int i = 0;i<n;i++) {
      	cin >>a[i];
      	if(i==0)
          	continue;
      	if(tochu!=0) {
          	if(tochu==1 && a[i-1] > a[i] || tochu == 2 && a[i-1] < a[i]){
            	c++;
              	tochu = 0;
            }
        } else {
          	if(a[i] == a[i-1])
              	continue;
      		else
              	tochu = (a[i] > a[i-1] ? 1 : 2);
        }
    }
  	cout << c <<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
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;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };


int main()
{
  int X,Y,Z,K;
  cin >> X >> Y >> Z >> K;
  vll A,B,C;
  rep(i,X){
      ll a;
      cin >> a;
      A.push_back(a);
  }
  rep(i,Y){
      ll b;
      cin >> b;
      B.push_back(b);
  }
  rep(i,Z){
      ll c;
      cin >> c;
      C.push_back(c);
  }

  vll AB;
  rep(i,X){
      rep(j,Y){
          AB.push_back(A[i]+B[j]);
      }
  }
  sort(AB.begin(),AB.end(),greater<ll>());
  AB.resize(K);//ABの上位K個までしかいらない、それ以下は結局Cを足してもKに入らない
  
  vll ABC;
  rep(i,Z){
      for(auto j:AB){
           ABC.push_back(j+C[i]);
      }
  }
  
  sort(ABC.begin(),ABC.end(),greater<ll>());

  rep(i,K){
      fin(ABC[i]);
  }

}



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

int main() {
    int n, m, x;
    int a[20][20], c[20];

    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }

    int ans = 1<<30;
    int all = 1<<n;
    for (int mask = 0; mask < all; mask++) {
        int level[20] = {};
        int cost = 0;
        for (int i = 0; i < n; i++) {
            if ((mask >> i) & 1) {
                cost += c[i];
                for (int j = 0; j < m; j++) level[j] += a[i][j];
            }
        }

        bool master = true;
        for (int i = 0; i < m; i++) {
            if (level[i] < x) master = false;
        }

        if (master) ans = min(ans, cost);
    }

    if (ans == 1 << 30) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main() {
    
    string s;
    cin>>s;
    int ans=s.size();
    int tmp=0;
    rep(i,s.size()){
        if(s[i]=='S'){
            tmp++;
        } else {
            tmp--;
            if(tmp<0)tmp=0;
            else ans-=2;
        }
    }
    fin(ans);
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i) {
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  // 左の子、自分、右の子で値が最大のノードを選ぶ
  if ( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= H && A[r] > A[largest] ) largest = r;

  if ( largest != i ) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int main() {
  cin >> H;

  for ( int i = 1; i <= H; i++ ) cin >> A[i];

  for ( int i = H / 2; i >= 1; i-- ) maxHeapify(i);

  for ( int i = 1; i <= H; i++ )
    cout << " " << A[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 4964
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  int N,K;
  cin>>N>>K;
  int ch=(N-1)*(N-2)/2;
  if(ch<K){cout<<-1;return 0;}
  int g=ch-K;
  queue<P>qu;
  rep(i,N-1){
    qu.push(P(1,i+2));
  }
  int flag=0; 
  repp(i,2,N+1){
    if(flag==1){break;}
    repp(j,i+1,N+1){
      if(g==0){flag=1;}
      if(flag==1){break;}
      g--;
      qu.push(P(i,j));
    }
  }
  cout<<qu.size()<<endl;
  while(!qu.empty()){
    auto t=qu.front();qu.pop();
    cout<<t.first<<' '<<t.second<<endl;
  }
}

Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define nrep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;

int main(){
	int n;
	scanf("%d",&n);
	vi a,b,c;
	rep(i,n){
		int x;scanf("%d",&x);
		a.push_back(x);
	}
	rep(i,n){
		int x;scanf("%d",&x);
		b.push_back(x);
	}
	rep(i,n){
		int x;scanf("%d",&x);
		c.push_back(x);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	ll ret=0;
	rep(i,n){
		int key=b[i];
		int anum=(int)(lower_bound(a.begin(),a.end(),key)-a.begin());
		int cnum=(int)(c.end()-upper_bound(c.begin(),c.end(),key));
		ret+=anum*(ll)cnum;
	}
	cout<<ret<<endl;
	return 0;
}



Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
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; }

int main(void){
  int a,b,k; cin >> a >> b >> k;
  for(int i = 100; i >= 1; i--){
    if(a%i == 0 && b%i == 0){
      k--;
    }
    if(k == 0){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int l, r, d;
    int count = 0;
    scanf("%d%d%d", &l, &r, &d);
    if (l % d == 0) {
        count++;
    }
    count += r / d;
    count -= l / d;
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <queue>
using namespace std;

struct Process {
  string name_;
  int time_;
};

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

  queue<Process> qq;
  for(int i = 0; i < n; i++) {
    Process process;
    cin >> process.name_ >> process.time_;
    qq.push(process);
  }

  int elapsed_time = 0;
  while(!qq.empty()) {
    auto process = qq.front();
    qq.pop();

    if(process.time_ <= q) {
      elapsed_time += process.time_;
      cout << process.name_ << " " << elapsed_time << endl;
    } else {
      elapsed_time += q;
      process.time_ -= q;
      qq.push(process);
    }
  }
}



Measured memory_bytes: 6332
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long
const int inf = 1 << 30;
#define INF 1e+9
#define MAX_V 100008


int main(){
  int n; cin >> n;
  if (n % 1000 == 0){
    cout << 0 << endl;
    return 0;
  }
  cout << 1000 - n % 1000 << endl;
}


Measured memory_bytes: 3636
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		
		int p=sc.nextInt();
		int q=sc.nextInt();
		String a[]=new String[p];
		String b[]=new String[q];
		for(int i=0;i<p;i++) {
			a[i]=sc.next();
		}
		for(int i=0;i<q;i++) {
			b[i]=sc.next();
		}
		String ans="No";
		for(int i=0;i<=p-q&&ans!="Yes";i++) {
			for(int j=0;j<=p-q&&ans!="Yes";j++) {
				if(a[i].substring(j,j+q).equals(b[0])) {
					ans="Yes";
					for(int k=i;k<i+q;k++) {
						if(!a[k].substring(j,j+q).equals(b[k-i])) {
							
							ans="No";
						}
						
					}
				if(ans=="Yes") {
					break;
				}
				}
			}
		}
		
		
        System.out.println(ans);
		
	}
	
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// void exclude(std::vector<char> a){
//   bool used=0;
//   for(int i=0;i<a.size();i++){
//     auto it = find(v.begin(), v.end(), a[i]);
//     if(it != v.end()){
//       if(!used){
//         used=1;
//       }else{
//         v.erase(it);
//       }
//     }
//   }
// }

int n,m;
std::vector<char> v;
string dp[10100];

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  cin>>n>>m;
  for(int i=0;i<m;i++){
    char t;cin>>t;
    v.push_back(t);
  }
  // sort(v.begin(), v.end());
  // exclude({'1','4'});
  // exclude({'5','3','2'});
  // exclude({'7','9','6'});
  // m = v.size();

  int mp[] = {0,2,5,5,4,5,6,3,7,6};

  for(int i=0;i<=n;i++){
    if(i&&dp[i]=="")continue;
    for(int j=0;j<m;j++){
      char num = v[j];
      int nx = i + mp[num-'0'];
      string new_s = dp[i] + num;
      sort(new_s.rbegin(), new_s.rend());
      if(new_s.size()>dp[nx].size() || (new_s.size()==dp[nx].size() && new_s>dp[nx])){
        dp[nx] = new_s;
      }
    }
  }

  cout<<dp[n]<<endl;

  return 0;
}


Measured memory_bytes: 27008
N = int(input())
X = list(map(int, input().split()))

ans = 10**18
ans_ = 0

for P in range(1, max(X) + 1):
    ans_ = 0
    for x in X:
        ans_ += (x - P) ** 2
    ans = min(ans, ans_)

print(ans)


Measured memory_bytes: 9168
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n, m;
    cin >> n >> m;

    vector< vector<int> > g(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        g[--a].emplace_back(--b);
        g[b].emplace_back(a);
    }

    int q;
    cin >> q;

    vector<int> v(q), d(q), c(q);
    rep(i, q){
        cin >> v[i] >> d[i] >> c[i];
        --v[i];
    }

    vector< vector<int> > dp(n, vector<int>(11, -1));
    rep(i, q){
        dp[v[i]][d[i]] = i;
    }

    rreps(j, 10){
        rep(i, n){
            chmax(dp[i][j - 1], dp[i][j]);
            for(auto to : g[i]){
                chmax(dp[to][j - 1], dp[i][j]);
            }
        }
    }

    rep(i, n){
        if(dp[i][0] < 0){
            cout << 0 << endl;
        }else{
            cout << c[dp[i][0]] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 16248
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

class UnionFind {
public:
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}

  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }

  void unite(int x, int y) {
    int px = find(x);
    int py = find(y);
    if (px != py) {
      if (data[py] < data[px]) swap(px, py);
      data[px] += data[py]; data[py] = px;
    }
  }
};


int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n+1);
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    uf.unite(x, y);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (uf.data[i] < 0) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


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

	if(X <= 599) cout << "8" << endl;
	else if(X <= 799) cout << "7" << endl;
	else if(X <= 999) cout << "6" << endl;
	else if(X<=1199) cout << "5" << endl;
	else if(X<=1399) cout << "4" << endl;
	else if(X<=1599) cout << "3" << endl;
	else if(X<=1799) cout << "2" << endl;
	else cout << "1" << endl;
	return 0;
}



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

typedef long long int lli;
#define N_MAX 100000

lli n, k;
lli h[N_MAX];
lli min_cost[N_MAX];

int main(void){
    // Your code here!
    cin >> n;
    cin >> k;
    for(int i = 0; i < n; i ++) cin >> h[i];
    
    for(int i = 0; i < n; i ++){
        // 足場iに到達する時の最小コストを調べる
        if (i >= k){
            lli min_val = min_cost[i-1] + abs(h[i] - h[i-1]);
            for(int j = 2; j <= k; j ++){
                lli cmp = min_cost[i-j] + abs(h[i] - h[i-j]);
                if (min_val > cmp) min_val = cmp;
            }
            min_cost[i] = min_val;
        }else if(i == 0){
            min_cost[0] = 0;
        }else{
            lli min_val = min_cost[i-1] + abs(h[i] - h[i-1]);
            for(int j = i-2; j >= 0; j --){
                lli cmp = min_cost[j] + abs(h[i] - h[j]);
                if (min_val > cmp) min_val = cmp;
            }
            min_cost[i] = min_val;
        }
    }
    cout << min_cost[n-1];
}

Measured memory_bytes: 1792
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		//int ans = 35;
		Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
	        int ans = sc.nextInt();
			
			int a,b,c,d;
			int sum = 0;
			int count = 0;
			
			for (a=0; a<10; a++){
				for (b=0; b<10; b++){
					for(c=0; c<10; c++){
						for(d=0; d<10; d++){
							sum = a + b + c + d;
							
							if (sum == ans){
								count ++;
							}
						}
					}
				}
			}
			
			System.out.println(count);
       	
       	}
       	
	}
}

Measured memory_bytes: 17028
a,b=map(int,input().split())
s=input()
ans=0
for i in range(a+b+1):
    if i==a and s[i]=="-":
        ans+=1
    elif i!=a and s[i].isdecimal()==True:
        ans+=1
if ans==a+b+1:
    print("Yes")
else:
    print("No")

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  char ca, cb, cc, cd;
  cin >> ca >> cb >> cc >> cd;
  int a = ctoi(ca), b = ctoi(cb), c = ctoi(cc), d = ctoi(cd);
  char n = '+', m = '+', l = '+';
  if (a+b+c+d==7) {
  } else if (a+b+c-d==7) {
    l = '-';
  } else if (a+b-c+d==7) {
    m = '-';
  } else if (a+b-c-d==7) {
    m = '-';
    l = '-';
  } else if (a-b+c+d==7) {
    n = '-';
  } else if (a-b+c-d==7) {
    n = '-';
    l = '-';
  } else if (a-b-c+d==7) {
    n = '-';
    m = '-';
  } else if (a-b-c-d==7) {
    n = '-';
    m = '-';
    l = '-';
  }
  cout << a << n << b << m << c << l << d << "=7" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int count = 0;
			Map map = new HashMap<String, Integer>();
			int max = 1;
			for (int i = 0; i < N; i++) {
				String tmp = in.next();
				if (!map.containsKey(tmp)) {
					map.put(tmp, 1);
				} else {
					int val = (int) map.get(tmp);
					val++;
					map.put(tmp, val);
					if (max < val) {
						max++;
					}
				}
			}
			TreeMap<String, Integer> tree = new TreeMap<>(map);
			for (String key : tree.keySet()) {
				if (tree.get(key) == max) {
					System.out.println(key);
				}
			}

		}
	}

	static boolean permutation_2(String s, String t) {
		if (s.length() != t.length()) {
			return false;
		}

		int[] letters = new int[256];

		char[] s_array = s.toCharArray();
		for (char c : s_array) {
			letters[c]++;
		}

		for (int i = 0; i < t.length(); i++) {
			int c = (int) t.charAt(i);
			if (--letters[c] < 0) {
				return false;
			}
		}
		return true;
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 76960
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var s = cin.next();

            
            Console.WriteLine((s[2] == s[3] && s[4] == s[5])? "Yes":"No");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

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

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

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

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

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

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

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


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

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
    char ste[4];
    scanf("%s",ste);
    if (ste[0]==ste[1] && ste[0]==ste[2])
    {
        printf("No");
    }else{
        printf("Yes");
    }
    
    return 0;
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;



int main() {
    int n; cin >> n;
    int a=0, w=0, t=0, r=0;
    rep(i, n) {
        string s; cin >> s;
        if(s == "AC") a++;
        if(s == "WA") w++;
        if(s == "TLE") t++;
        if(s == "RE") r++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func main() {
	var n, k int
	var s string

	fmt.Scan(&n)
	fmt.Scan(&k)
	fmt.Scan(&s)

	first := 0
	for i := 1; i < n; i++ {
		if s[i-1] == s[i] {
			first++
		}
	}

	if first+2*k < n {
		fmt.Println(first+2*k)
	} else {
		fmt.Println(n-1)
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n; cin >> n;
    long long sum = 0;
    for(long long i=1;i<=n;++i){
        if(i%3==0 && i%5==0) continue;
        else if(i%5==0) continue;
        else if(i%3==0) continue;
        else sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3592
#![allow(unused_imports)]
#![allow(dead_code)]

use std::thread;
use std::io::{ self, Read };
use std::fmt;
use std::iter::Iterator;
use std::cmp::*;
use std::collections::*;
use std::str::*;

#[derive(Default)]
struct Input {
    buf: Vec<String>
}

impl Input {
    fn new() -> Input {
        Input { buf: Vec::new() }
    }

    fn read<T: FromStr>(&mut self) -> T 
    where <T as FromStr>::Err: fmt::Debug {
        self.next().unwrap().parse::<T>().unwrap()
    }

    fn read_bytes(&mut self) -> Vec<u8> {
        self.next().unwrap().into_bytes()
    }

    fn read_n<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where <T as FromStr>::Err: fmt::Debug {
        let mut v = Vec::new();
        for _ in 0..n { v.push(self.read::<T>()); }
        v
    }
}

impl Iterator for Input {
    type Item = String;
    fn next(&mut self) -> Option<String> {
        while self.buf.is_empty() {
            let mut s = String::new();
            let _res = io::stdin().read_line(&mut s);
            self.buf = s.split_whitespace().map(|s| s.to_owned()).collect::<Vec<_>>();
            self.buf.reverse();
        }
        self.buf.pop()
    }
}

fn run() {
    let mut ip = Input::new();
    let mut s = ip.read_bytes();
    s[3] = b'8';
    println!("{}", from_utf8(&s).unwrap());
}

fn main() {
    let _ = thread::Builder::new()
        .stack_size(10 * 1024 * 1024)
        .spawn(run).unwrap()
        .join();
}

Measured memory_bytes: 8572
def magic2():
    # A < B < C
    A, B, C = map(int, input().split())
    K = int(input())
    
    if A < B < C:
        print("Yes")
        return
    for i in range(K):
        if B <= A:
            B *= 2
        elif C <= B:
            C *= 2
            
        if A < B < C:
            print("Yes")
            break
            
    else:
        print("No")
        
magic2()
        

Measured memory_bytes: 9180
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            for (int i = 0;; i++)
            {
                if (N-111*(i+1)<=0)
                {
                    Console.WriteLine(111*(i+1));
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 11092
<?php
list($n, $m) = explode(' ', trim(fgets(STDIN)));

$lmax = 1;
$rmin = $n;
for ($i = 0; $i < $m; $i++) {
    list($l, $r) = explode(' ', trim(fgets(STDIN)));
    $lmax = max($lmax, $l);
    $rmin = min($rmin, $r);
}

echo max($rmin - $lmax + 1, 0);

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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using i32 = int;
using i64 = long long;

using namespace std;


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

    i32 m,k;cin >> m >> k;

    // obvious
    if(k >= (1 << m)){
        cout << -1 << '\n';
        return 0;
    }

    if(m == 0){
        cout << "0 0" << '\n';
        return 0;
    }
    if(m == 1){
        if(k == 0)cout << "1 1 0 0" << '\n';
        else cout << -1 << '\n';
        return 0;
    }else{
        for(i32 i = 0;i < (1 << m);i++){
            if(i != k)cout << i << ' ';
        }
        cout << k << ' ';
        for(i32 i = (1 << m) - 1;i >= 0;i--){
            if(i != k)cout << i << ' ';
        }
        cout << k << '\n';
    }
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    
    int a,b;
    while (cin >> a >> b && a || b)
    {
        int cnt = 0;
        for (int i = 1; i <= a; i++){
            for (int j = i+1; j <= a; j++){
                for (int k = j+1; k <= a; k++){
                    if (i+j+k==b)
                    {
                        cnt++;
                    }
                    
                }
                
            }
            
        }
    cout << cnt << endl;    
    }
    
    
    
    
    return 0;
}




Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){
    ll h,w;cin>>h>>w;
    string a[h];rep(i,0,h-1)cin>>a[i];
    string alp="qwertyuiopasdfghjklzxcvbnm";
    sort(alp.begin(),alp.end());
    ll c[26];rep(i,0,25)c[i]=0;
    rep(i,0,h-1){
        rep(j,0,w-1){
            rep(k,0,25){
                if(a[i][j]==alp[k]){
                    c[k]++;
                    break;
                }
            }
        }
    }
    ll ok1,ok2;
    if(h%2==1 && w%2==1){
        ok1=1;
        ok2=(h-1)/2+(w-1)/2;
    }else if(h%2==0 && w%2==0){
        ok1=0;
        ok2=0;
    }else if(h%2==0 && w%2==1){
        ok1=0;
        ok2=h/2;
    }else{
        ok1=0;
        ok2=w/2;
    }
    rep(i,0,25){
        if(c[i]%4==0){
            continue;
        }else if(c[i]%4==2){
            ok2--;
            if(ok2<0){
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            ok1--;
            if(ok1<0){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int a,b;
  char op;
  cin>>a>>op>>b;
  if(op=='+'){
    cout<<a+b<<endl;
  }else{
    cout<<a-b<<endl;
  }
}

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

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

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

void solve() {
    ll L, R, res, mod = 2019;
    cin >> L >> R;
    res = (L % mod * R % mod) % mod;
    ll tail = min(L + 2019, R);
    for (ll l = L; l <= tail; l++) {
        for (ll r = l + 1; r <= tail; r++) {
            res = min(res, (l % mod * r % mod) % mod);
        }
    }
    cout << res << endl;
}

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


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(15);
    cout << fixed;

    int n = 0;
    cin >> n;

    vector<int> v(n - 1);
    for (auto &i : v)
        cin >> i;
    
    v.push_back(INT_MAX);

    int ans = 0;
    ans += v.front();
    for (int i = 0; i < v.size() - 1; i++) {
        ans += min(v[i], v[i + 1]);
    }
    
    cout << ans << '\n';

    return 0;
}

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

public class Solution
{
    public static void Main()
    {
        var a = int.Parse(Console.ReadLine());
        var b = int.Parse(Console.ReadLine());

        for (int i = 1; i <= 3; i++)
        {
            if(i != a && i != b)
            {

                Console.WriteLine(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 11092
#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 <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <memory>        // unique_ptr, shared_ptr, weak_ptr

using namespace std;

using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;

#define _LIBCPP_DEBUG 0
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
    int n, d1, d2, cnt=0;
    bool f = false;

    cin >> n;
    for (size_t i=0; i<n; i++) {
        cin >> d1 >> d2;
        if (d1 == d2) cnt++;
        else cnt = 0;

        if (cnt == 3) {
            f = true;
            break;
        }
    }
    
    if (f) cout << "Yes"  << endl;
    else cout << "No"  << endl;
    return 0;
}


Measured memory_bytes: 3132
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	llint n;
	cin >> n;
	vector<string>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	llint cnt[5] = {};
	rep(i, n) {
		if (a[i][0] == 'M')cnt[0]++;
		if (a[i][0] == 'A')cnt[1]++;
		if (a[i][0] == 'R')cnt[2]++;
		if (a[i][0] == 'C')cnt[3]++;
		if (a[i][0] == 'H')cnt[4]++;
	}
	llint ans = 0;
	llint tmp;
	rep(i, 10) {
		tmp = 1;
		if (0 <= i&&i <= 5) {
			tmp *= cnt[0];
		}
		if (0 <= i&&i <= 2 || 6 <= i&&i <= 8) {
			tmp *= cnt[1];
		}
		if (i == 0 || i == 3 || i == 4 || i == 6 || i == 7 || i == 9) {
			tmp *= cnt[2];
		}
		if (i == 1 || i == 3 || i == 5 || i == 6 || i == 8 || i == 9) {
			tmp *= cnt[3];
		}
		if (i == 2 || i == 4 || i == 5 || 7 <= i&&i <= 9) {
			tmp *= cnt[4];
		}
		ans += tmp;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N,M;
  cin >> N;
  vector<string> s(N);
  for(int i=0; i<N; i++){
    cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for(int i=0; i<M; i++){
    cin >> t.at(i);
  }
  
  int k=0,l=0;
  for(int i=0; i<N; i++){
    for(int j=i; j<N; j++){
      if(s.at(i)==s.at(j)){
        k++;
      }
    }
    for(int j=0; j<M; j++){
      if(s.at(i)==t.at(j)){
        k--;
      }
    }
    l=max(l,k);
    k=0;
  }
  cout << l << endl;
}


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

int main()
{
	int h, w;
	while (cin >> h >> w, !(w == 0 && h == 0)) {
		if (h == 1)cout << "#" << endl;
		else {

			for (int x = 0; x < w; x++) {
				cout << "#";
			}
			cout << endl;
			for (int y = 1; y < h - 1; y++) {
				cout << "#";
				for (int x = 1; x < w - 1; x++) {
					cout << ".";
				}
				cout << "#" << endl;
			}
			for (int x = 0; x < w; x++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll m,d;
    cin>>m>>d;
    ll ans=0;
    for(ll i=10;i<=d;i++){
        ll d1=i%10;
        ll d10=i/10;
        if(d1>=2&&d10>=2&&d1*d10<=m){
//            cout<<d1<<" "<<d10<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

int main(){

    ll int n,w;
    cin>>n>>w;
    pair<ll int,ll int> values[n];
    for(ll int i = 0;i<n;i++){
        cin>>values[i].first>>values[i].second;
    }
    ll int dp[n+1][w+1];
    memset(dp,0,sizeof(dp));
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=w;j++){

            if(j<values[i-1].first)
                dp[i][j] = dp[i-1][j];
            else{

                dp[i][j] = max(dp[i-1][j],values[i-1].second+dp[i-1][j-values[i-1].first]);

            }

        }
    }

    cout<<dp[n][w]<<endl;

}





Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio();
	cin.tie(0);
	int l,r;cin>>l>>r;
	if(r-l+1>=2019) cout<<0<<endl;
	else{
		l%=2019;
		r%=2019;
		if(r<l) r+=2019;
		int ans=2020;
		for(int i=l;i<=r;i++)
			for(int j=i+1;j<=r;j++){
				ans=min(ans,(i*j)%2019);
			}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
//a, b = [1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11]
//x, y = map(int, input().split())
//print("Yes" if (x in a and y in a) or (x in b and y in b) else "No")
#include <iostream>
using namespace std;
int main(){
 int a[] = {1, 3, 5, 7, 8, 10, 12};
 int b[] = {4, 6, 9, 11};
 int x, y;
 cin >> x >> y;
 bool xflg = false;
 bool yflg = false;
 for(auto i: a){
  if(i == x && !xflg) xflg = true;
  if(i == y && !yflg) yflg = true;
 }
 if(xflg && yflg) {cout << "Yes" << endl; return 0;}

 xflg = false;
 yflg = false;
 for(auto i: b){
  if(i == x && !xflg) xflg = true;
  if(i == y && !yflg) yflg = true;
 }
 if(xflg && yflg) {cout << "Yes" << endl; return 0;}
 cout << "No" << endl;
}


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

using namespace std;

typedef long long ll;
bool comp(pair<ll,ll> p1,pair<ll,ll> p2)
{
	return p1.second<p2.second;

}

signed main()
{
ll n,k;
	vector<pair<ll,ll> > v;
	cin>>n>>k;

ll x,y;
	while(n--)
	{
		cin>>x>>y;
		v.push_back({x,y});
	}
	
ll index=0;

	sort(v.begin(),v.end());
	for(ll i=0;i<v.size();i++)
	{

	ll val=v[i].first;
	ll amount=v[i].second;
		index+=amount;
		if(index>=k)
		{	cout<<val<<'\n';
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    ll before = 1, tmp = 0, sum = a[0];

    if(a[0] < 1) {
        tmp += 1 - a[0];
        sum = 1;
    }
    for(int i = 1; i < n; i++) {
        sum += a[i];
        before *= -1;
        if(sum == 0) {
            sum = before;
            tmp++;
        }
        if(before != (sum / llabs(sum))) {
            tmp += llabs(before) + llabs(sum);
            sum = before;
        }
    }
    ll ans = tmp;

    before = -1, tmp = 0, sum = a[0];
    if(a[0] > -1) {
        tmp += 1 + a[0];
        sum = -1;
    }
    for(int i = 1; i < n; i++) {
        sum += a[i];
        before *= -1;
        if(sum == 0) {
            sum = before;
            tmp++;
        }
        if(before != (sum / llabs(sum))) {
            tmp += llabs(before) + llabs(sum);
            sum = before;
        }
    }
    ans = min(ans, tmp);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1024
import sys


def input(): return sys.stdin.readline().strip()


N, M = (list)(map(int, input().split()))
edge = []

for _ in range(M):
    edge.append((list)(map(int, input().split())))


inf = 10**15

d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N-1):
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d

for a, b, c in edge:
    c = -c
    new_d = d[a]+c
    if d[b] > new_d:
        d[b] = new_d
        if b == N:
            print('inf')
            exit()
print(-d[-1])


Measured memory_bytes: 3572