akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define p 1000000007
using namespace std;
namespace ywy{
	inline ll mi(int a,int b){
		ll ans=1,tmp=a;while(b){
			if(b&1)ans=(ans*tmp)%p;tmp=(tmp*tmp)%p;b>>=1;
		}return(ans);
	}int jc[5000001],jcny[5000001],dp[2022][2022];
	inline ll cnm(int n,int m){
		if(n<m)return(0);ll cjr=jc[n];cjr*=jcny[m];cjr%=p;cjr*=jcny[n-m];return(cjr%p);
	}
	inline void pre(int n){
		jc[0]=1;for(register int i=1;i<=n;i++)jc[i]=((ll)jc[i-1]*i)%p;jcny[n]=mi(jc[n],p-2);
		for(register int i=n-1;i>=0;i--)jcny[i]=((ll)jcny[i+1]*(i+1))%p;
	}
	void ywymain(){
		int n,k;cin>>n>>k;if(k==1){
			cout<<1<<endl;return;
		}pre(n*k);dp[1][0]=dp[1][1]=1;for(register int i=2;i<=n;i++){
			for(register int j=i;j>=0;j--){
				if(!j)dp[i][j]=dp[i][j+1];else{
					dp[i][j]=(dp[i][j+1]+((dp[i-1][j-1]*(ll)i)%p)*cnm(i*k-j-1,k-2))%p;
				}
			}
		}cout<<dp[n][0]<<endl;
	}
}
int main(){
	ywy::ywymain();return(0);
}

Measured memory_bytes: 48512
#95 C
A,B,C,X,Y =map(int,input().split())
honest = A * X + B * Y

if X >= Y:
    diff = C * min(X,Y) * 2 + A * (X-Y)
else:
    diff = C * min(X,Y) * 2 + B * (Y -X)
max_ =C * max(X,Y) * 2

print(min(honest,diff,max_))


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        
        // board[i][j]: 迷路
        char[][] board = new char[h][w];
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                board[i][j] = str.charAt(j);
            }
        }
        
        // visited[i][j]: 当該マスを既に通ったか否か
        boolean[][] visited = new boolean[h][w];
        
        // 上下左右
        int[] dx = new int[]{1, 0, -1, 0};
        int[] dy = new int[]{0, 1, 0, -1};
        
        // steps = BFS((0, 0)→(h, w)までの最短経路の深さ)
        int steps = -1;
        Queue<int[]> que = new ArrayDeque<int[]>();
        que.add(new int[]{0, 0, 0});
        while (!que.isEmpty()) {
            int[] cur = que.poll();
            int x = cur[0];
            int y = cur[1];
            int depth = cur[2];
            
            if (x == h - 1 && y == w - 1) {
                steps = depth;
                break;
            }
            
            // 移動可能ならそのマスに深さ+1を配ってキューに入れる
            for (int k = 0; k < 4; k++) {
                int nx = x + dx[k];
                int ny = y + dy[k];
                int ndepth = depth + 1;
                
                if (0 <= nx && nx < h && 0 <= ny && ny < w &&
                    board[nx][ny] == '.' && !visited[nx][ny]) {
                    que.add(new int[]{nx, ny, ndepth});
                    visited[nx][ny] = true;
                }
            }
        }
        if (steps == -1) {
            System.out.println(-1);
            return;
        }
        
        // ans = 通行不能にしてもよいマス数
        // a = 全マス数, b = 通行に必要なマス数, c = 既に通行不能なマス数
        int ans = 0;
        int a = 0, b = 0, c = 0;
        a = h * w;
        b = steps + 1;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (board[i][j] == '#') {
                    c++;
                }
            }
        }
        ans = a - b - c;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
use std::io::Read;

fn run() {
    let (s, t): (Vec<usize>, Vec<usize>) = {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        let mut it = s.trim().split_whitespace();
        let s = it.next().unwrap().chars().map(|c| c as usize - 'a' as usize).collect();
        let t = it.next().unwrap().chars().map(|c| c as usize - 'a' as usize).collect();
        (s, t)
    };
    let mut index = vec![vec![]; 26];
    for (i, c) in s.iter().enumerate() {
        index[*c].push(i);
    }
    let n = s.len();
    for a in index.iter_mut() {
        if a.len() == 0 {
            continue;
        }
        let f = a[0];
        a.push(f + n);
    }
    let mut now = n - 1;
    let mut ans = 0;
    for t in t {
        if index[t].len() == 0 {
            println!("-1");
            return;
        }
        let k = match index[t].binary_search(&(now + 1)) {
            Ok(k) => k,
            Err(k) => k,
        };
        ans += index[t][k] - now;
        now = index[t][k] % n;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 8444
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
using namespace std;

#ifndef ConanYu
#define CPPIO
#endif
#ifdef CPPIO
#define endl '\n'
#endif

#define push_back emplace_back
template<typename T>
class List : public vector<T>
{
public:
//  new
    template<typename... U>
    List(const U &... tail) : vector<T>(0)
    {
        pb(tail...);
    }

//  push_back
    void pb() {}
    template<typename... U>
    void pb(const T & head, const U &... tail)
    {
        this->push_back(head);
        pb(tail...);
    }

//print
    void print()
    {
        const int LEN = this->size();
        for (int i = 0; i < LEN; i++)
        {
            cout << (*this)[i] << (i == LEN - 1 ? '\n' : ' ');
        }
    }
};

template<typename T>
ostream & operator << (ostream & out, const vector<T> & vec)
{
    const int n = vec.size();
    out << '[';
    for (int i = 0; i < n; i++)
    {
        out << vec[i] << (i == n - 1 ? "]" : ", ");
    }
    return out;
}

typedef long long ll;
typedef pair<int, int>pii;
typedef pair<long long, long long>pll;
typedef long double ld;

pll exgcd(const long long x, const long long y)
{
    if (!y)
    {
        return make_pair(1, 0);
    }
    pll cur = exgcd(y, x % y);
    return make_pair(cur.second, cur.first - (x / y) * cur.second);
}

const long long __mod__ = 998244353;

long long mod(long long x, long long p = __mod__)
{
    return ((x % p) + p) % p;
}

long long mmod()
{
    return 1LL;
}

template <typename T, typename ...U>
long long mmod(const T &head, const U &... tail)
{
    return mod(head * mmod(tail...), __mod__);
}

void print() {}
template <typename T, typename... U>
void print(const T &head, const U &... tail)
{
    cout << head << (sizeof...(tail) ? ' ' : '\n');
    print(tail...);
}

#ifdef ConanYu
#define debug(...) print(__VA_ARGS__)
#else
#define debug(...) 0
#endif

inline long long fmul(long long a, long long c, const long long& Mod = __mod__)
{
    a %= Mod, c %= Mod ;
    return (a * c - (long long)(((long double) a * c + 0.5) / Mod) * Mod) % Mod ;
}

long long gcd(long long x, long long y)
{
    return y == 0 ? x : gcd(y, x % y);
}

long long fpow(long long a, long long b, const long long & p = __mod__)
{
    ll ans = 1LL;
    for (a %= p; b; a = a * a % p, b >>= 1)
    {
        if (b & 1)
        {
            ans = ans * a % p;
        }
    }
    return ans;
}

void solve();
int main()
{
#ifdef ConanYu
    freopen("test.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // freopen("2.in", "r", stdin);
    // freopen("2.out", "w", stdout);
    clock_t st = clock();
#endif

#ifdef CPPIO
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif

    solve();

#ifdef ConanYu
    clock_t ed = clock();
    cerr << "time: " << ((ed - st) * 1.0 / CLOCKS_PER_SEC) << endl;
#endif
    return 0;
}

// *********************************************************************************************************

void solve()
{
    int n, m;
    cin >> n >> m;
    print(n + m / 2);
}

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

int main() {
	
	int n;
	cin >> n;
	string ans = "No";
	if(n % 10 == 9 || (n/10) % 10 == 9) ans = "Yes";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>

using namespace std;

const int MAX = 51;
const int BLACK = 100;
const int WHITE = 200;
int cnt[MAX][MAX],w,h;
char map[MAX][MAX];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

void init(){
  memset(cnt,0,sizeof(cnt));
}

bool inside(int x, int y){
  return 0<=x&&x<w&&0<=y&&y<h;
}
void solve(int y,int x, int c){

  if(cnt[y][x] == BLACK+WHITE) return;
  if(c == BLACK && cnt[y][x] == BLACK) return;
  if(c == WHITE && cnt[y][x] == WHITE) return;

  cnt[y][x]+=c;

  for(int i = 0; i < 4; i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    if(inside(nx,ny)){
      if(map[ny][nx] == '.')solve(ny,nx,c);
    }
  }
}

int main(){

  while(cin >> w >> h && w+h){

    init();
    for(int i = 0; i < h; i++)
      for(int j = 0; j < w; j++)
	cin >> map[i][j];

    for(int i = 0; i < h; i++)
      for(int j = 0; j < w; j++){
	if(map[i][j] == 'W') solve(i,j,WHITE);
	if(map[i][j] == 'B') solve(i,j,BLACK);
      }
    int bb = 0,ww = 0;

    for(int i = 0; i < h; i++)
      for(int j = 0; j < w; j++){
	if(map[i][j] == '.' && cnt[i][j] == BLACK) bb++;
	if(map[i][j] == '.' && cnt[i][j] == WHITE) ww++;
      }

    cout << bb << " " << ww << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,b,c,d=0,e=0,f,g,h;
  cin >> a >> b >> c;
  rep(i,c){
    cin >> f >> g >> h;
    if(h==1) d = max(d,f);
    if(h==2) a = min(a,f);
    if(h==3) e = max(e,g);
    if(h==4) b = min(b,g);
  }
  if(d<=a&&e<=b)cout << (d-a) * (e-b);
  else cout << 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//BEGIN CUT HERE
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
//END CUT HERE
//INSERT ABOVE HERE
signed main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  vector<int> vs({a,b,c,d,e});
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++)
      if(abs(vs[i]-vs[j])>k) drop(":(");
  drop("Yay!"s);
  return 0;
}
/*
  verified on 2019/07/08
  https://atcoder.jp/contests/abc123/tasks/abc123_a
*/


Measured memory_bytes: 256
import math

N,D = map(int,input().split())
S = []
for i in range(N):
    S.append(list(map(int,input().split())))
    
count = 0
for j in S:
    if math.sqrt(j[0]**2 + j[1]**2) <= D:
        count += 1

print(count)

Measured memory_bytes: 45372
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
const double PI=3.14159265358979323846;
//小数点以下を指定したい時　　  cout << fixed << setprecision();
int main(){
     cout << fixed << setprecision(15);
    int a,b,h,m,ans;cin>>a>>b>>h>>m;
    double k=2*PI*m/60,l=2*PI*(60*h+m)/720;
    double p=max(k,l)-min(k,l),q=min(p,2*PI-p);
    double t=cos(q);
    double c=sqrt(a*a+b*b-2*a*b*t);
    cout<<c<<endl;
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n, i, j, k, a[100002];
    bool vis[100002] = {false};
    cin >> n >> k;
    for(i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(i = 0; i <= k; i++) {
        for(j = 0; j < n; j++) {
            if(i >= a[j] && !vis[i - a[j]]) {
                vis[i] = true;
            }
        }
    }
    if(vis[k]) {
        cout << "First" << endl;
    }
    else {
        cout << "Second" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;

bool inside(int x,int y,int w,int h){
  return (x >= 0 && y >= 0 && x < w && y < h);
}

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

int w,h,maxv = 0;
string mas[25];
int dist[25][25];
  
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> h >> w;
    rep(i,h){
      cin >> mas[i];
    }
    queue<pii> que;
    rep(na,h){
      rep(su,w){
	if(mas[na][su] != '#'){
	  memset(dist,INF,sizeof(dist));
	  dist[na][su] = 0;
	  que.emplace(na,su);
	  while(!que.empty()){
	    int x,y;
	    tie(x,y) = que.front();
	    que.pop();
	    
	    rep(i,4){
	      int nx = x + dx[i];
	      int ny = y + dy[i];
	      if(inside(nx,ny,h,w) && dist[nx][ny] > dist[x][y] + 1 && mas[nx][ny] != '#'){
		dist[nx][ny] = dist[x][y] +1;
		que.emplace(nx,ny);
	      }
	    }
	  }
	  rep(i,h){
	    rep(j,w){
	      if(dist[i][j] != INF){
		maxv = max(maxv,dist[i][j]);
	      }
	    }
	  }
	}
      }
    }
    cout << maxv << '\n';
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a, b = [list(map(int, input().split())) for _ in range(2)]
bSum = 0
for i in range(n):
    if a[i] >= b[i]:
        bSum += b[i]
        a[i] -= b[i]
    elif a[i] + a[i + 1] >= b[i]:
        bSum += b[i]
        a[i + 1] -= b[i] - a[i]
        a[i] = 0
    else:
        bSum += a[i] + a[i + 1]
        a[i + 1] = 0

print(bSum)


Measured memory_bytes: 19156
#include <stdio.h>
int main(void){
    long long int n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);

    if(a == 0){
        printf("0");
        return 0;
    }

    long long int r, ans;
    r = n % (a + b);

    if(r <= a){
        ans = n / (a + b) * a + r;
        printf("%lld", ans);
        return 0;
    }else{
        ans = n / (a + b) * a + a;
        printf("%lld", ans);
    }
}

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

int main(){
  int N;cin>>N;
  int t[110000],x[110000],y[110000];
  t[0]=x[0]=y[0]=0;
  for (int i=0;i<N;++i)cin>>t[i+1]>>x[i+1]>>y[i+1];
  
  bool can=true;
  for (int i=0;i<N;++i){
    int dt=t[i+1]-t[i];
    int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(dt<dist)can=false;
    if(dist%2 != dt%2)can=false;
  }
  if (can)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
#define endl '\n'
//char a[2000][2000];
using namespace std;
ll countDivisibles(ll A, ll B, ll M) 
{ 
    // Add 1 explicitly as A is divisible by M 
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
  
    // A is not divisible by M 
    return (B / M) - (A / M); 
} 
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);            
    //std::setprecision(20);    
    int tests=1;
      //freopen("input.txt", "r", stdin);   
    //cin>>tests;
  while(tests--)
    { 
       int n,k;
       cin>>n>>k;
       vector<pair<int,int> >v;
       for(int i = 1;i<n;i++){
        v.pb({n,i});
       }
       if(k > (n-1)*(n-2)/2){
        cout<<-1;
        exit(0);
       }
       else{
        ll l = (n-1)*(n-2)/2;
        int i = 1,j=1;
        while(l > k){
            if(i+1 < n){
            v.pb({j,i+1});
                l--;
            i++;
            }
            else{
                j++;
                i = j;
            }
            
        }       
        //j++;
        //i = j;
        //cout<<l<<" "; 
       }
      // cout<<endl;
       cout<<v.size()<<endl;
       for(int i = 0;i<v.size();i++)
        cout<<v[i].F<<" "<<v[i].S<<endl ;
    }
}


Measured memory_bytes: 384
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 

const int N = 2e5 + 123;
const int M = 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int Sz = 501;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}

int n;
ll a[N], b[N];
ll ans;

void solve() { 
  cin >> n;
  for (int i = 1;i <= n;i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = n;i;i--) {
    a[i] += ans;
    ll now = a[i] / b[i];
    if (now * b[i] == a[i]) continue;
    now++;
    ans += now * b[i] - a[i];
  }
  cout << ans << endl;
}

int main() {
  #ifdef wws
   freopen("in", "r", stdin);
   // freopen("in", "w", stdout);
  #endif 
  ios_base::sync_with_stdio(0);
  int tt = 1; 
  while(tt--) solve();
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  long long int a,b,x,count=0;

  scanf("%lld",&a);
  scanf("%lld",&b);
  scanf("%lld",&x);

  if(a != 0){
    count = b/x - (a-1)/x;
  }else{
    count = b/x+1;
  }

  printf("%lld",count);

  return 0;
}


Measured memory_bytes: 128
import scala.io.StdIn.readInt

object Main {
  val r = Array(2,3,5,7)

  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }

  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toLong

      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,BigInt(x).modPow(2,n).toLong, i, d, s, n)
    }
  }

  def repeat(j:Int, x:Long, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,BigInt(x).modPow(2,n).toLong,i,d,s,n)
  }

  def isPrime(n:Int):Boolean = {
    if(n<4500) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    println((0 until n).count{ _=> {
        val m = readInt; isPrime(m)
      }
    })
  }
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> ls(n);
    rep(i, n) {
        int l;
        cin >> l;
        ls[i] = l;
    }
    sort(ls.begin(), ls.end());
    int sum = accumulate(ls.begin(), ls.end() - 1, 0);
    cout << (sum > ls[n - 1] ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
s = list(input())[::-1]
n = len(s)
mod = 10**9 + 7

t = [[0 for j in range(13)] for i in range(n)]
for i,x in enumerate(s):
    A = pow(10, i ,13)
    if i == 0:
        if x == "?":
            for j in range(0,10):
                t[i][j] += 1
        else:
            t[i][int(x)] += 1
    else:
        if x == "?":
            for k in range(13):
                for j in range(10):
                    b = (k + j*A)%13
                    t[i][b] += t[i-1][k]
                    t[i][b] %= mod
        else:
            for k in range(0,13):
                b = (k + int(x)*A)%13
                t[i][b] += t[i-1][k]
                t[i][b] %= mod
print(t[-1][5]%mod)


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

int n;
string s;

int main(void){
  cin >> n >> s;
  int res = 0;
  for(int i = 0; i < 1000; i++){
    stringstream ss;
    ss << setw(3) << setfill('0') << i;
    string m = ss.str();
    int p, q, r;
    p = 0;
    while(p < n && s[p] != m[0]) p++;
    q = p+1;
    while(q < n && s[q] != m[1]) q++;
    r = q+1;
    while(r < n && s[r] != m[2]) r++;
    if(r < n) res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3676
#include<stdio.h>
void ac(char *str,int *a){
  if(str[0]=='A' && str[1]=='C'){
    *a = *a+1;
  }
}

void wa(char *str,int *w){
  if(str[0]=='W' && str[1]=='A'){
    *w = *w+1;
  }
}

void tle(char *str,int *t){
  if(str[0]=='T' && str[1]=='L' && str[2]=='E'){
    *t = *t+1;
  }
}

void re(char *str,int *r){
  if(str[0]=='R' && str[1]=='E'){
    *r = *r+1;
  }
}

int main(){
  int n,i,a=0,w=0,t=0,r=0;
  char str[4];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",str);
    ac(str,&a);
    wa(str,&w);
    tle(str,&t);
    re(str,&r);
  }

  printf("AC x %d\n",a);
  printf("WA x %d\n",w);
  printf("TLE x %d\n",t);
  printf("RE x %d\n",r);
 return 0;
}

Measured memory_bytes: 2152
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll n;
    ll d;
    cin >> n >> d;
    ll x,y;
    ll count = 0;
    for (ll i =0;i <n;i++) {
        cin >> x >> y;
        if (sqrt(x*x + y*y) <=d) count++;
    }
    cout << count << endl;

}

Measured memory_bytes: 3164
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int m = in.nextInt();
		int f = in.nextInt();
		int r = in.nextInt();
		
		while(m!=-1 || f!=-1 || r!=-1){
			if(m==-1 || f==-1){
				System.out.println("F");
			}else if(m+f >= 50){
				if(m+f >= 80){
					System.out.println("A");
				}else if(m+f>=65 && m+f<80){
					System.out.println("B");
				}else{
					System.out.println("C");
				}
			}else{
				if(m+f >= 30){
					if(r>=50){
						System.out.println("C");
					}else{
						System.out.println("D");
					}
				}else{
					System.out.println("F");
				}
			}
			
			m = in.nextInt();
			f = in.nextInt();
			r = in.nextInt();
		}
	}
}

Measured memory_bytes: 19232
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define  pb(x) push_back(x)
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define mod 1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
int main()
{
	sync;
	string s,t;
	cin>>s>>t;

	vector<ll>v[26];
	
	for(ll i=0;i<s.length();i++)
	v[s[i]-'a'].push_back(i+1);
	
	ll ans=0,ind=0;
	
	for(ll i=0;i<t.length();i++)
	{
		if(!v[t[i]-'a'].size())
		return cout<<-1,0;

		if(ind>=v[t[i]-'a'][v[t[i]-'a'].size()-1])
		{
			ans+=s.length();
			ind=v[t[i]-'a'][0];
			continue;
		}
		
		ll low=0,high=v[t[i]-'a'].size()-1,hind=-1;
		
		while(low<=high)
		{
			ll mid=(low+high)/2;
			if(v[t[i]-'a'][mid]>ind)
			high=mid-1,hind=mid;
			else
			low=mid+1;
		}
		ind=v[t[i]-'a'][hind];
	}
	ans+=ind;
	cout<<ans;
}

Measured memory_bytes: 1736
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;






int main(){


        long double W,H,x,y;
        cin >> W >> H >> x >> y;


        long double ans = (W*H)/2;
        printf("%.14Lf", ans);
        cout << " ";
        if(x == W/2 && y == H/2) cout << 1 << endl;
        else cout << 0 << endl;

}




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

using namespace std;

const int N = (1 << 13) + 5;
const int M = 1e3 + 15;

int f[M][N];

int a[M];
int b[M];
int x[M];

int main() {
  int n, m;
  cin >> n >> m;
  memset(f, 0x3f3f, sizeof(f));
  for (int i = 1; i <= m; ++i) {
    cin >> a[i] >> b[i];
    int msk = 0;
    for (int j = 1; j <= b[i]; ++j) {
      int k;
      cin >> k;
      msk |= 1 << (k - 1);
    }
    
    x[i] = msk;
  }

  f[0][0] = 0;

  int ans = 0x3f3f3f3f;

  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < (1 << n); ++j) {
      f[i + 1][j | x[i + 1]] = min(f[i + 1][j | x[i + 1]], f[i][j] + a[i + 1]);
    }
    for (int j = 0; j < (1 << n); ++j) {
      f[i + 1][j] = min(f[i + 1][j], f[i][j]);
    }
    ans = min(ans, f[i + 1][(1 << n) - 1]);
  }
  if (ans == 0x3f3f3f3f) {
    puts("-1");
    return 0;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 32768
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(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, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int M = in.nextInt();
            if (N == M)
                out.print("Yes");
            else
                out.print("No");
        }

    }
}



Measured memory_bytes: 21844
#include <stdio.h>
int main(void)
{
	long long int a,b,tmp;
	while(1){
	    int i=1,r;
		scanf("%lld %lld",&a,&b);
		if(a==0&&b==0) break;
		if(a<b){
			tmp=a;
			a=b;
			b=tmp;
		}
		r=a%b;
        while(r!=0){
	        a=b;
	        b=r;
	        r=a%b;
	        i++;
        }
		printf("%lld %d\n",b,i);
	}
	return 0;
}


Measured memory_bytes: 2028
#!/usr/bin/env python3
import fractions
from functools import reduce


def main():
    N = int(input().strip())
    A = [int(x) for x in input().strip().split()]
    lcm = lcm_list(A) - 1
    print(f(lcm, A))

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def f(m, A):
    result = 0
    for i in A:
        result += m % i
    return result


if __name__ == '__main__':
    main()


Measured memory_bytes: 5332
n = int(input())
p = list(map(int, input().split()))

counter = 0
for i in range(1, n-1):
    _p = [p[i-1], p[i], p[i+1]]

    if (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1]):
        counter += 1
print(counter)


Measured memory_bytes: 38512
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
	int n,k,num=1;
	cin>>n>>k;
	for (int i = 0; i < n; i++) {
		if(i==0)num*=(k);
		else num*=k-1;
	}
	cout<<num<<"\n";

	return 0;
}


Measured memory_bytes: 256
# -*-coding:utf-8

def main():

    n, m, l = map(int, input().split())
    A = []
    B = []

    for i in range(n):
        A.append(list(map(int, input().split())))

    for i in range(m):
        B.append(list(map(int, input().split())))

    Ans = []
    for i in range(n):
        row = []
        for j in range(l):
            rowSum = 0
            for k in range(m):
                rowSum += A[i][k] * B[k][j]
            row.append(rowSum)

        Ans.append(row)

    for i in range(n):
        print(' '.join([str(a) for a in Ans[i]]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 8896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b >=c) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n; cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 0) continue;

    int cnt = 0;
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) {
        cnt++;
      }
    }
    if (cnt == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long m=1e9+7;

long long power(long long x, long long y, long long p)
{
    long long res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

long long modInverse(long long n, long long p)
{
    return power(n, p-2, p);
}

long long nCrModPFermat(long long n, long long r, long long p)
{
   if (r==0)
      return 1;
    long long fac[n+1];
    fac[0] = 1;
    for (long long i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;
    return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;
}

int main()
{
	string s,t;
    cin>>s>>t;
    cout<<t+s<<endl;
}


Measured memory_bytes: 256
/*



#include <iostream>
#include <array>
using namespace std;

//0~12,13~25,26~38,39~51
int main(void) {

int n;
cin >> n;
array<bool,52> flag;
flag.fill(false);
char Mark;
int Number =0 ;
//?????£??????????????????????????°????????????
for (int i = 0; i < n; i++){
cin >> Mark>>Number;
if (Mark == 'S'){
flag[Number-1] = true;
}
else if (Mark == 'H'){
flag[Number+12] = true;
}
else if (Mark == 'C'){
flag[Number + 25] = true;
}
else if (Mark == 'D'){
flag[Number + 38] = true;
}
}
//?????£??????????????????????????¨???

for (int i = 0; i < 13; i++){

if (flag[i] == false){
cout << "S " << i + 1 << endl;

}


}

for (int i = 0; i < 13; i++){

if (flag[i + 13] == false){
cout << "H " << i + 1 << endl;

}
}
for (int i = 0; i < 13; i++){

if (flag[i+26] == false){
cout << "C " << i + 1 << endl;

}
}

for (int i = 0; i < 13; i++){

if (flag[i+39] == false){
cout << "S " << i + 1 << endl;

}
}
//system("pause");
return 0;
}
*/


#include<iostream>
using namespace std;
int main(void){
	int loop_num, i, j;
	char mark;
	int num;
	char mark_box[4] = {'S','H','C','D'};

	bool all_card[4][13] = {};
	cin >> loop_num;
	for (i = 0; i < loop_num; i++){
		cin >> mark;
		cin >> num;
		switch (mark){
		case 'S':
			all_card[0][num - 1] = true;
			break;
		case 'H':
			all_card[1][num - 1] = true;
			break;
		case 'C':
			all_card[2][num - 1] = true;
			break;
		case 'D':
			all_card[3][num - 1] = true;
			break;

		}
	}
	
	for (i = 0; i < 4; i++){
		for (j = 0; j < 13; j++){
			if (all_card[i][j] == false){
				cout << mark_box[i] << " " << j + 1 << endl;
			}
		}

	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }

#define int long long
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for (int i=0;i<(n);++i)
#define forit(beginIt, endIt) for(auto it=(beginIt);it!=(endIt);++it)

using namespace std;

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

  string s; cin >> s;

  if (s > "2019/04/30") cout << "TBD" << endl;
  else cout << "Heisei" << endl;
  
  // int num = 0;
  // int n;
  // cin >> n;
  // vector<int> v(n);
  // forit (v.begin(), v.end()) cin >> *it;
  // for (auto it = v.begin(); it < v.end(); ++it) num += *it;
  // cout << num << endl;

  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i,n) for( int i=0 ; i<n ; i++ )
#define f(i, a, b) for( int i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define mod 1000000007
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll fact(ll n)
{
    ll ans = 1e14;
    for(ll i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll sol = (i - 1) + (n/i - 1);
            ans = min(ans,sol);
        }
    }
    return ans;
}
int visited[200000] = {0};
vector<vector<int> > v(200000);
int dfs(int x)
{
    int ans = 0;
    if(visited[x]==0)
    {
        visited[x] = 1;
        ans++;
        int a = v[x].size();
        for(int j = 0; j<a; j++)
        {
            int data = v[x][j];
            ans = ans + dfs(data);
        }
    }
    return ans;
}
void primefactors(int n)
{
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            cout << i << " ";
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        cout << n << " ";

}
double fib(int n)
{
    double sol1,sol2;
    sol1 = (1 + sqrt(5))/2;
    sol2 = (1 - sqrt(5))/2;
    sol1 = pow(sol1,n);
    sol2 = pow(sol2,n);
    double ans = sol1 - sol2;
    ans = ans/sqrt(5);
    //ans = int(ans);
    return ans;
}

ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}

ll index(ll n)
{
    n = double(n);
    double sol = n*n + n;
    sol = sol*2 + 1;
    double ans = -1 + sqrt(sol);
    ans = ans/2;
    ans = ll(ans);
    return ans;
}
int main()
{
    ll n;
    cin>>n;
    ll a = INT_MIN;//xi + yi max
    ll b = INT_MIN;//xi - yi max
    ll c = 10000000000;// xj + yj min
    ll d = 10000000000;// xj - yj min
    fi(i,n)
    {
        ll x,y;
        cin>>x>>y;
        a = max(a,x + y);
        b = max(b,x - y);
        c = min(c,x + y);
        d = min(d,x - y);
    }
    ll ans = max(a - c,b - d);
    cout<<ans;
}


Measured memory_bytes: 7764
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define INF 2e14
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 205

int n;
string adj[MAXN];
ll dist[MAXN][MAXN];

void Floyd()
{
	forn(i,0,n) forn(j,0,n){
		if(i==j) dist[i][j]=0;
		else dist[i][j]= adj[i][j]=='1'?1LL:INF;
	}
	forn(k,0,n) forn(i,0,n) forn(j,0,n)
		dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
}

int clr[MAXN];
bool bi=1;

void dfs(int u,int p){
	if(!bi) return;
	clr[u]=p;
	
	forn(i,0,n){
		if(adj[u][i]=='1'){
			if(clr[i]!=-1){
				if(clr[i]==p){
					bi=0;
					return;
				}
			}
			else dfs(i,p^1);
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	mset(clr,-1);
	
	cin>>n;
	forn(i,0,n) cin>>adj[i];
	
	dfs(0,0);
	if(!bi){
		cout<<-1<<'\n';
		return 0;
	}
	
	Floyd();
	
	ll ans=0;
	forn(i,0,n){
		forn(j,0,n){
			ans=max(ans,dist[i][j]);
		}
	}
	
	/*forn(i,0,n){
		forn(j,0,n){
			cout<<dist[i][j]<<" ";
		}
		cout<<'\n';
	}cout<<'\n';*/
	
	cout<<ans+1<<'\n';
	
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod=1e9+7;
int main(){
    ll n,a[200001],b[200001];
    cin>>n;
    rep(i,n) cin>>a[i],b[i]=a[i];
    ll sum=0,ans1=0,ans2=0;
    rep(i,n){
        if(i%2==0){
            sum+=a[i];
            if(sum<=0) ans1+=(-1)*sum+1,a[i]+=(-1)*sum+1,sum=1;
        }
        if(i%2){
            sum+=a[i];
            if(sum>=0) ans1+=sum+1,a[i]-=sum+1,sum=-1;
        }
        //cout<<a[i]<<"\n";
    }
    sum=0;
    rep(i,n){
        if(i%2==1){
            sum+=b[i];
            if(sum<=0) ans2+=(-1)*sum+1,b[i]+=(-1)*sum+1,sum=1;
        }
        if(i%2==0){
            sum+=b[i];
            if(sum>=0) ans2+=sum+1,b[i]-=sum+1,sum=-1;
        }
        //cout<<a[i]<<"\n";
    }
    cout<<min(ans1,ans2)<<"\n";
}

Measured memory_bytes: 3072
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
  int N;
  while (cin >> N) {
    vector<int> L(N);
    for (int i = 0; i < N; i++) cin >> L[i];
    int sum = accumulate(L.begin(), L.end(), 0);
    int mx = *max_element(L.begin(), L.end());
    bool res = (sum - mx) > mx;
    cout << (res ? "Yes" : "No") << endl;
  }
  return 0;
}


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

int main(){
	string table1 = "23456789TJQKA";
	char trump;
	while( cin >> trump && trump != '#' ){
		string table2 = "SHDC";
		remove(table2.begin(),table2.end(),trump);
		table2[table2.size()-1] = trump;
		vector< pair<pair<int,int>,int> > r[13];
		for(int j = 0 ; j < 4 ; j++){
			for(int i = 0 ; i < 13 ; i++){
				string str; cin >> str;
				r[i].push_back({{str[1],table1.find(str[0])},j});
			}
		}
		int win[2] = {};
		int nextLeader = 0;
		for(int i = 0 ; i < 13 ; i++){
			char led = r[i][nextLeader].first.first;
			for(int j = 0 ; j < 4 ; j++){
				r[i][j].first.first = ( trump == r[i][j].first.first ? 2 : led == r[i][j].first.first ? 1 : 0 );
			}
			sort(r[i].rbegin(),r[i].rend());
			nextLeader = r[i][0].second;
			win[r[i][0].second%2]++;
			
		}
		if( win[0] > 6 ){
			cout << "NS" << " " << win[0] - 6 << endl;
		}else{
			cout << "EW" << " " << win[1] - 6 << endl;
		}
	}
}

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

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}
//const int INF = 0x3f3f3f3f;
//const int mod=1e9+7;
//const double pi=3.14159265359;
//###################################################################
int main() {
    int n=D();
    string a;
    cin>>a;
    map<char,int>mp;
    for(int i=0;i<n;i++){
        mp[a[i]]++;
    }
    int r=0,w=0;
    for(int i=0;i<mp['R'];i++){
        if(a[i]=='W')r++;
    }
    for(int i=mp['R'];i<n;i++){
        if(a[i]=='R')w++;
    }
    cout<<max(r,w);

}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define LL long long
using namespace std;
const int N = 1e5 +10 ;
int n,q;
int a[N] ;
map <int,int> mp ;
LL sum = 0 ;
int main()
{
    ios::sync_with_stdio(0) ;
    cin.tie(0) ; cout.tie(0) ;
    //freopen("ch.inp","r",stdin) ;
    cin >> n ;
    FOR(i,1,n) cin >> a[i] ,sum += a[i] , mp[a[i]]++;
    cin >> q;
    FOR(i,1,q)
    {
        int x,y;
        cin >> x >> y ;
        sum += (y-x)*mp[x] ;
        mp[y] += mp[x] ;
        mp[x] = 0;
        cout << sum <<'\n';
    }

}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

struct Edge{
  int to;
  long long cost;
};
struct NODE{
  int pos;
  long long cost;
};

bool operator < (const NODE &a,const NODE &b){
  return a.cost > b.cost;
}
class dijkstra{
  public:
  const int MAX_V = 1000000;
  vector<Edge> g[100000],rg[100000];
  bool visit[100000];

  int N;
  const ll INF = 1e15;
  dijkstra(){};
  dijkstra(int n):N(n){};
  void push(int p,int to,int c){
    g[p].push_back({to,c});
    rg[to].push_back({p,c});
  }
  pll farthest_point(int n,int p){
    pll r = {0,n};
    for (auto&& k : g[n]) {
      if(k.to != p){
        pll res = farthest_point(k.to,n);
        res.fi += k.cost;
        if(r.fi < res.fi) r = res;
      }
    }
    return r;
  }
  ll diameter(){
    pll a = farthest_point(0,-1);
    pll b = farthest_point(a.se,-1);
    return b.fi;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll s,t,w;
  dijkstra d(n);
  rep(i,n-1){
    cin >> s >> t >> w;
    d.push(s,t,w);
    d.push(t,s,w);
  }
  cout << d.diameter() << endl;
  return 0;
}

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

def judge(x):
    if N-P<=x<=N-1:
        return True
    if A[x]+M<A[N-P]:
        return False
    
    cnt = 0
    
    for i in range(N):
        if i>=N-P+1:
            cnt += M
        else:
            cnt += min(M, A[x]+M-A[i])
    
    return cnt>=M*V

def binary_search():
    l, r = 0, N-1
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l

N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

print(N-binary_search())

Measured memory_bytes: 58736
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 ALL(v) v.begin(), v.end()
int n, m, l, q;
int a[10000];
ll d[300][300];
ll f[300][300];
void warshall_floyd(int n, ll f[300][300]) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
      }
    }
  }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m>>l;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=INF;
            f[i][j]=INF;
            if(i==j){
                d[i][j]=0;
                f[i][j]=0;
            }
        }
    }
    for (int i = 0; i < m; i++)
    {
        ll ai, bi, ci;
        cin >> ai>>bi>>ci;
        f[ai-1][bi-1]=ci;
        f[bi-1][ai-1]=ci;
    }
    warshall_floyd(n,f);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j&&f[i][j]<=l){
                d[i][j]=1LL;
            }
        }
    }
    warshall_floyd(n,d);
    /*
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout<<d[i][j]<<" "<<f[i][j]<<" ";
        }
        cout<<"\n";
    }*/
    cin>>q;
    vector<int> s, t;
    for(int i=0;i<q;i++){
        int t1, s1;
        cin>>t1>>s1;
        t.push_back(t1);
        s.push_back(s1);
    }
    for(int i=0;i<q;i++){
        if(d[t[i]-1][s[i]-1]<INF)
            cout<<d[t[i]-1][s[i]-1]-1<<"\n";
        else
            cout<<-1<<"\n";
    }
}


Measured memory_bytes: 2932