akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#define MOD 1000000007
using namespace std;
const int MAXN = 405;
int a[MAXN],b[MAXN],n,c,pow[MAXN][MAXN],sum[MAXN][MAXN],f[MAXN][MAXN];
typedef long long ll;
inline void init()
{	
	for(int i=1;i<=400;++i){
		pow[i][0]=1;
		for(int j=1;j<=400;++j)
			pow[i][j]=(ll)pow[i][j-1]*i%MOD;
	}
	for(int i=1;i<=400;++i)
		for(int j=0;j<=400;++j)
			sum[i][j]=(sum[i-1][j]+pow[i][j])%MOD;
}
inline void add(int &x,int a)
{
	x+=a;
	if(x>=MOD)x-=MOD;
}
int main()
{
	init();
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	for(int i=1;i<=n;++i)scanf("%d",b+i);
	f[0][0]=1;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=c;++j){
			if(!f[i-1][j])continue;
			for(int k=0;k<=c-j;++k){		   
				add(f[i][j+k],(ll)f[i-1][j]*((sum[b[i]][k]-sum[a[i]-1][k]+MOD)%MOD)%MOD);
			}
		}
	}
	cout<<f[n][c]<<endl;
	return 0;
}


Measured memory_bytes: 2176
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		k: usize,
		p: [usize; n],
		c: [isize; n],
	}

	let mut ans = -9999999999999;
	for start in 0..n {	// スタートマス
		let mut flag = vec![false; n];	// 一度来たマス
		let mut score = vec![0isize; n];	// n手までのスコア合計
		flag[start] = true;
		let mut i = start;
		let mut count = 0; 
		loop {
			i = p[i]-1;
			if count == 0 {
				score[count] = c[i];
			}
			else {
				score[count] = score[count-1] + c[i];
			}
			if flag[i] {
				break;
			}
			count += 1;
		}
		if k < count {
			//score.remove(0);
			//score.sort();
			let mut ans1 = -99999999999999;
			for i in 0..k {
				ans1 = max(ans1, score[i]);
			}
			ans = max(ans, ans1);
			//println!("(0-1) {}", ans1);
		}
		else {
			if score[count] <= 0 {
				//score.remove(0);
				//score.sort();
				let mut ans1 = -99999999999999;
				for i in 0..count {
					ans1 = max(ans1, score[i]);
				}
				ans = max(ans, ans1);
				//println!("(0-2) {}", ans1);
			}
			else {
				// (1) 端数の中に最大がある場合は、最大回数ループ＋最大値まで
				// 端数の中に最大がない場合は、
				// (2)-1 最大ループ＋端数の中の一番大きいところまで と、
				// (2)-2 最大ループ-1 ＋ 最大値 の大きい方

				let mut s1max = -9999999999999;
				let mut i1max = 0usize;
				let mut s2max = -9999999999999;
				//let mut i2max = 0usize;
				for i in 0..=count {
					if score[i] > s1max {
						s1max = score[i];
						i1max = i;
					}
					if i < k % (count+1) {
						if score[i] > s2max {
							s2max = score[i];
							//i2max = i;
						}
					}
				}
				// (1)
				if i1max < k % (count+1) {
					ans = max(ans, score[count]*(k/(count+1)) as isize + s1max);
					//println!("(1) {}", score[count]*(k/(count+1)) as isize + s1max)
				}
				else {
					// (2)-1
					let ans1 = score[count]*(k/(count+1)) as isize + s2max;
					let ans2 = score[count]*((k/(count+1)) as isize -1) + s1max;

					//println!("(2) max({},{})", ans1,ans2);

					ans = max(ans, max(ans1, ans2));
				}
			}
		}
	}
	println!("{}", ans);
}



Measured memory_bytes: 2368
import java.util.*;

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

        int[][] matrix = new int[h][w];
        for (int i = 0; i < h; i++) {
            String row = sc.nextLine();
            for (int j = 0; j < w; j++) {
                matrix[i][j] = row.charAt(j);
            }
        }

        int max = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (matrix[i][j] == '.') {
                    max = Math.max(max, bfs(matrix, h, w, i, j));
                }
            }
        }
        System.out.println(max);
    }

    private static int bfs(int[][] matrix, int h, int w, int i, int j) {
        int localMax = 0;
        int[][] dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
        Queue<int[]> q = new LinkedList<>();
        boolean[][] visited = new boolean[h][w];
        q.add(new int[] {i, j, 0});
        visited[i][j] = true;

        while (!q.isEmpty()) {
            int[] poll = q.poll();
            for (int[] dir : dirs) {
                int nx = poll[0] + dir[0];
                int ny = poll[1] + dir[1];

                if (nx >= 0 && nx < h && ny >= 0 && ny < w && matrix[nx][ny] == '.' && !visited[nx][ny]) {
                    int nc = poll[2] + 1;
                    visited[nx][ny] = true;
                    localMax = Math.max(localMax, nc);
                    q.add(new int[] {nx, ny, nc});
                }
            }
        }
        return localMax;
    }
}

Measured memory_bytes: 32828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9 + 7;
const int INF = 1e9;
int used[100000];

struct edge{
	int to, num;
};

int main(){
	int N, s, t; cin >> N >> s >> t;
	s--; t--;
	vector<edge> G[N];
	for(int i=0; i<N-1; i++){
		int u, v; cin >> u >> v;
		u--; v--;
		G[u].push_back({v, i});
		G[v].push_back({u, i});
	}
	vector<int> d(N, INF);
	vector<int> d2(N, INF);
	d[s] = 0;
	queue<int> que;
	que.push(s);
	while(que.size()){
		int aa = que.front(); que.pop();
		for(int i=0; i<G[aa].size(); i++){
			if(d[G[aa][i].to] == INF){
				d[G[aa][i].to] = d[aa] + 1;
				que.push(G[aa][i].to);
			}
		}
	}
	d2[t] = 0;
	queue<int> qu;
	qu.push(t);
	while(qu.size()){
		int aa = qu.front(); qu.pop();
		for(int i=0; i<G[aa].size(); i++){
			if(d2[G[aa][i].to] == INF){
				d2[G[aa][i].to] = d2[aa] + 1;
				qu.push(G[aa][i].to);
			}
		}
	}
	int ans = 0;
	for(int i=0; i<N; i++){
		if(d[i] < d2[i]){
			if(ans < d2[i] - 1) ans = d2[i] - 1;
		}
	}
	cout << ans  << endl;
	return 0;
}


Measured memory_bytes: 7168
/* Date: 28/03/2020
 * Author: @codingoo
 * Problem Name: A - Changing a Character
 * Platform: Atcoder
 */
 #include <bits/stdc++.h>
 #define lli long long int
 #define ll long long
 #define endl "\n"
 using namespace std;

 int main() {
     int n, k;
     cin >> n >> k;
     string s;
     cin >> s;
     for (int i=0; i<s.length(); i++) {
        if ((i+1) == k)
            s[i] = (char)(s[i]+32);
        cout << s[i];
     }
     return 0;
}


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

using namespace std;

int main(){
    string S;
    cin >> S;

    if (S.size()==1){
        cout << "YES" << endl;
        return 0;
    }

    vector<int> cnt(3,0);
    for(int i=0; i<S.size(); i++){
        int n = S[i]-'a';
        cnt[n]++;
    }
    int max_ = *max_element(cnt.begin(),cnt.end());
    int min_ = *min_element(cnt.begin(),cnt.end());
    string ans = "NO";
    if (S.size()==1 && max_!=2){
        ans = "YES";
    }else if(max_-min_<2){
        ans="YES";
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

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 T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;


int main()
{

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


	int n; cin >> n;
	vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i];
	if (n % 2 == 0) {
		vector dp(2, vector(2, vector<ll>(2, -INF)));
		auto init = [&](int idx) {
			for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) dp[idx][i][j] = -INF; 
		};
		int cur = 0;
		int nxt = 1;
		dp[0][0][0] = 0;
		for (int i = 0; i < n; i++) {
			init(nxt);
			for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) {
				//とる
				if (k == 0) chmax(dp[nxt][j][1], dp[cur][j][0] + a[i]);
				if (k == 1) chmax(dp[nxt][j][0], dp[cur][j][k]);
				//とらない
				if (j == 0) {
					chmax(dp[nxt][j + 1][0], dp[cur][j][k]);
				}
			}
			swap(cur, nxt);
		}
		ll res = -INF; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) chmax(res, dp[cur][i][j]);
		cout << res << "\n";
	}
	else {
		vector dp(2, vector(3, vector<ll>(2, -INF)));
		auto init = [&](int idx) {
			for (int i = 0; i < 3; i++) for (int j = 0; j < 2; j++) dp[idx][i][j] = -INF;
		};
		int cur = 0;
		int nxt = 1;
		dp[0][0][0] = 0;
		for (int i = 0; i < n; i++) {
			init(nxt);
			for (int j = 0; j < 3; j++) for (int k = 0; k < 2; k++) {
				//とる
				if (k == 0 and !(j == 0 and i == n - 1)) chmax(dp[nxt][j][1], dp[cur][j][0] + a[i]);
				if (k == 1) chmax(dp[nxt][j][0], dp[cur][j][k]);
				//とらない
				if (j < 2) {
					if(k == 0) chmax(dp[nxt][j + 1][0], dp[cur][j][k]);
				}
			}
			swap(cur, nxt);
		}
		ll res = -INF; for (int i = 1; i < 3; i++) for (int j = 0; j < 2; j++) chmax(res, dp[cur][i][j]);
		cout << res << "\n";
	}
	return 0;
}

Measured memory_bytes: 4760
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;

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

#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll N;
	cin >> N;
	vector<P> pos(N);
	for_each(ALL(pos), [](P &a)->void{cin >> a.first >> a.second;});

	map<P, ll> mp;
	REP(i, N){
		P top = pos[i];
		REP(j, N){
			P end = pos[j];
			ll eX = end.first - top.first;
			ll eY = end.second - top.second;
			mp[P{eX, eY}]++;
		}
	}

	ll ans = INF;
	for (auto one : mp) {
		auto pq = one.first;
		ll ansOne = 0;
		vector<bool> isUsed(N, false);
		REP(i, N) {
			P stPos = pos[i];
			if (isUsed[i])  continue;
			isUsed[i] = true;
			ansOne++;
			if (pq == P{0, 0})  continue;

			queue<P> que;
			que.push(P{ stPos.first + pq.first, stPos.second + pq.second });
			que.push(P{ stPos.first - pq.first, stPos.second - pq.second });
			while (!que.empty()) {
				P nextPos = que.front(); que.pop();
				REP(j, N){
					if (!isUsed[j]) {
						if (pos[j] == nextPos) {
							isUsed[j] = true;
							que.push(P{ pos[j].first + pq.first, pos[j].second + pq.second });
							que.push(P{ pos[j].first - pq.first, pos[j].second - pq.second });
						}
					}
				}
			}
		}
		ans = min(ans, ansOne);
	}

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


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<queue>
#include<deque>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001
using namespace std;
typedef long long ll;

int a,b,c;
int x,y;

int main(){
  std::cin >> a>>b>>c>>x>>y;
  int res = MAX;
  int tmp;
  rep(i,0,max(x,y)+1){
    tmp = a * max(0,(x-i))+ b * max(0,(y-i)) + 2*c*i;
    res = min(res, tmp);
  }

  std::cout << res << '\n';
}


Measured memory_bytes: 384
N = int(input())
M = 10
L = 2*M
A = [[0 for _ in range(L+1)] for _ in range(L+1)]

for _ in range(N):
  y = float(input())
  x = y
  x *= 10.**M
  x = int(x+0.1)
  k_2 = 0
  while x % 2 == 0 and k_2 < 2*M:
    x = x // 2
    k_2 += 1
  k_5 = 0 
  while x % 5 == 0 and k_5 < 2*M:
    x = x // 5
    k_5 += 1
  A[k_2][k_5] += 1

ans = 0
for k_2 in range(L+1):
  for k_5 in range(L+1):
    for l_2 in range(k_2, L+1):
      for l_5 in range(L+1):
        if k_2+l_2 >= 2*M and k_5+l_5 >= 2*M:
          if k_2 == l_2 and k_5 == l_5:
            ans += A[k_2][k_5]*(A[k_2][k_5]-1)//2
          elif l_2 > k_2 or (k_2 == l_2 and k_5 < l_5):
            ans += A[k_2][k_5]*A[l_2][l_5]          
#print(A)
print(ans)

Measured memory_bytes: 9516
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
int F[MAX_N][10];
int P[MAX_N][11];

signed main(){
    int N; cin >> N;
    for(int i=0; i<N; ++i){
        for(int j=0; j<10; ++j){
            cin >> F[i][j];
        }
    }
    for(int i=0; i<N; ++i){
        for(int j=0; j<11; ++j){
            cin >> P[i][j];
        }
    }
    long long ans = -(1<<30);
    for(int bit=1; bit < (1<<10); ++bit){
        long long tmp_res = 0;
        for(int i=0; i<N; ++i){
            int ci = 0;
            for(int j=0; j<10; ++j){
                if(F[i][j] && (bit>>j & 1) ) ++ci;
            }
            tmp_res += P[i][ci];
        }
        if(tmp_res>ans){
            ans = tmp_res;
        } 
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if ((b - a) == (c - b)) {
		printf("YES\n");
		return 0;
	}
	else {
		printf("NO\n");
		return 0;
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SP << " " 

using namespace std;

void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	long long int a, b, c, k;
	cin>> a >> b >> c >> k;

	if(k<=a) cout<< k << endl;
	else if(k<=a+b) cout<< a << endl;
	else cout<< a-(k-a-b) <<endl;
 
	return 0;
}

Measured memory_bytes: 3632
# https://atcoder.jp/contests/abc079/tasks/abc079_a

import itertools
import collections
import bisect

def main():
    N = list(input())

    if N[1] == N[2] and (N[0] == N[1] or N[2] == N[3]):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double 
#define foi(a,n) for(int i = a; i < n; i++)
#define ee 1000000007
#define pb push_back

ll fast(ll base, ll power, ll mod=ee){
    ll ans =1;
    base%=mod;
    while(power){
        if(power&1){
            ans*=base;
            ans%=mod;
        }
        base*=base;
        base%=mod;
        power>>=1;
    }
    return ans;
}

void solve() {
    ll n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for(auto &x: v){
		cin >> x.first >> x.second;
	}
	int mx1 = -ee, mx2 = -ee, mx3 = -ee, mx4 = -ee, mn1 = ee, mn2 = ee, mn3 = ee, mn4 = ee;
	for(int i = 0; i < n; i++){
		mx1 = max(mx1, v[i].first + v[i].second);
		mn1 = min(mn1, v[i].first + v[i].second);
		mx2 = max(mx2, v[i].first - v[i].second);
		mn2 = min(mn2, v[i].first - v[i].second);
	}
	cout << max(mx1-mn1, mx2 - mn2);
}

int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    //~ cin >> t;
    while(t--){
		solve();
		//~ cout << '\n';
	}
}


Measured memory_bytes: 4760
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <stack>
#include <cstdio>
#include <complex>
#include <iomanip>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define show(x) cout << #x << " = " << x << endl;
int G[101][101];
int GG[101][101];
int main(){
    int n,m;
    cin >> n >> m;
    int a,b,c;
    rep(i,100){
        rep(j,100){
            G[i][j]=10000000;
        }
    }
    rep(hoge,m){
        cin >> a >> b >> c;
        a--,b--;
        G[a][b] = c;
        G[b][a] = c;
        GG[a][b]=c;
        GG[b][a]=c;
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(GG[i][j]!=0&&G[i][j]!=GG[i][j]){
                //cout << i << " " << j << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
//..........................SHIVANSHU MISHRA............................
//..............CODED WITH LOVE.........................................
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl           '\n'
#define F              first
#define S              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define P             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define N                 100005
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif*/
}
int32_t main() {
    c_p_c();
    double n;
    cin >> n;
    double k;
    k = n / 1000;
    k = ceil(k);
    int ans;
    if (n > 1000) {
        ans = k * 1000 - n;
    }
    else {
        ans = (1000 - n);
    }
    cout << abs(ans) << endl;
    return 0;
}

Measured memory_bytes: 3796
#include <stdio.h>
int main(void){
    long long int n,m,c;
    scanf("%lld %lld",&n,&m);
  	if((n-2)*(m-2) < 0){
  		printf("%lld", (2-n)*(m-2));
    }else{
    	printf("%lld", (n-2)*(m-2));
    }
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [0] + list(map(int, input().split()))

for i in range(N, 0, -1):
    tmp = 0
    j = i
    while j < N+1:
        tmp += A[j]
        j += i
    A[i] = tmp % 2
ans = []
for i, j in enumerate(A):
    if j == 1:
        ans.append(i)

print(len(ans))
print(*ans)


Measured memory_bytes: 12716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll,ull;
int b[2005];
int main()
{ 
	int n,x,y;
	cin>>n>>x>>y;
	int k;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)		
		{
			k=min(min(abs(j-i),abs(i-x)+1+abs(j-y)),abs(i-y)+1+abs(j-x));
			b[k]++;	
		}
	}
	for(int i=1;i<n;i++)
	{
		cout<<b[i]<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S;
	char word[26];
	cin >> S;
	for (int i = 0; i < S.length(); i++) {
		word[i] = S[i];
	}

	for (int i = 0; i < S.length(); i++) {
		for (int j = i+1; j < S.length(); j++) {
			if (word[j] == S[i]) {
				cout << "no" << "\n";
				return 0;
			}
		}
	}

	cout << "yes" << "\n";
	return 0;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define per(i,n) for (int i=n-1; i>=0; --i)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<int>;
using vv = vector<vi>;
const int mod = 1000000007;
//const int mod = 998244353;

struct mint{
    ll x;
    mint(ll x=0):x(x%mod){}
    
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x-= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }
    
    //modが素数の場合
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    mint sum = a[0], ans = 0;
    for(int i=1; i<n; i++){
        ans += sum * a[i];
        sum += a[i];
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 4808
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

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

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////



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

	ll N = 50;

	ll p = K / N;
	ll q = K % N;

	cout << N <<endl;

	rep(i, q) {
		cout << N - 1 + p + (N + 1 - q) << " ";
	}

	rep(i, N - q) {
		cout << N - 1 + p - q << " ";
	}

	system("PAUSE");
}






Measured memory_bytes: 504
/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000
//cin.ignore (7777, '\n');

using namespace std;
using namespace __gnu_pbds;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}      
  private:
    bool first;
    string separator;
};
 
template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

double massiv[200];
ll n;

int main(){
FAST_READ;
cin>>n;
for(ll i=1;i<=n;i++)cin>>massiv[i];
double niz=0.0;
for(ll i=1;i<=n;i++)
{
  niz+=(1.0/massiv[i]);	
}

cout<<1.0/niz<<endl;






return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll a[100001],b[100001];
pint s[100001];
int main(){
    int n;
    cin>>n;
    rep(i,n){
        cin>>a[i]>>b[i];
        s[i]={a[i]+b[i],i};
    }
    sort(s,s+n,greater<pint>());
    ll ans=0;
    rep(i,n){
        if(i&1) ans+=-b[s[i].second];
        else ans+=(ll)s[i].first-b[s[i].second];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll ch[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll k;
	cin>>k;
	k--;
	cout << ch[k];
	// your code goes here
	return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>

int main(void){
    int x,r,d,i;
    r=0,d=0,x=0,i=0;

    scanf("%d %d %d",&r,&d,&x);

    for(i=1;i<=10;i++){

        x=r*x-d;

        printf("%d\n",x);
    }

    return 0;
}

Measured memory_bytes: 128
using System;

public class Answer {
    private static void Main(string[] args) {
        string input = Console.ReadLine();
        string output = GetAnswer(input);

        Console.WriteLine(output);
    }

    private static string GetAnswer(string input) {
        string output = "";

        int number = int.Parse(input);

        int hours = number / (60 * 60);
        number -= hours * (60 * 60);

        int minutes = number / 60;
        number -= minutes * 60;

        int seconds = number;

        output = $"{hours}:{minutes}:{seconds}";

        return output;
    }
}


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

using namespace std;

const int max_x = 100;
const int shift = max_x / 2;
const long long inf = 5000111222000111222LL;
constexpr int val[3] = {2, 3, 5};
constexpr int mx_p[3] = {65, 45, 33};

int t, num[mx_p[0]][mx_p[1]][mx_p[2]];
long long n, a[3], d;
vector<long long> pw[3];
long long dp[13111][max_x];

long long mul(long long x, long long y) {
    if (!x || !y) {
        return 0;
    }
    if (x > inf / y) {
        return inf;
    }
    return x * y;
}

void upd(int i, int x, long long val) {
    if (dp[i][x] == -1) {
        dp[i][x] = val;
    } else {
        dp[i][x] = min(dp[i][x], val);
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    for (int i = 0; i < 3; ++i) {
        pw[i].push_back(1);
        while (mul(val[i], pw[i].back()) < inf) {
            pw[i].push_back(pw[i].back() * val[i]);
        }
        //cout << pw[i].size() << endl;
    }
    vector<int> ids[3];
    vector<long long> vals;
    memset(num, -1, sizeof(num));
    for (int i = 0; i < pw[0].size(); ++i) {
        for (int j = 0; j < pw[1].size(); ++j) {
            for (int k = 0; k < pw[2].size(); ++k) {
                long long val = mul(pw[0][i], mul(pw[1][j], pw[2][k]));
                if (val < inf) {
                    num[i][j][k] = ids[0].size();
                    ids[0].push_back(i);
                    ids[1].push_back(j);
                    ids[2].push_back(k);
                    vals.push_back(val);
                }
            }
        }
    }
    //cout << ids[0].size() << endl;
    cin >> t;
    while (t--) {
        cin >> n >> a[0] >> a[1] >> a[2] >> d;
        memset(dp, -1, sizeof(dp));
        dp[num[0][0][0]][shift] = 0;
        long long ans = inf;
        for (int i = 0; i < ids[0].size(); ++i) {
            for (int x = 0; x + 1 < max_x; ++x) {
                if (dp[i][x] == -1) {
                    continue;
                }
                upd(i, x + 1, dp[i][x] + d);
            }
            for (int x = max_x - 1; x; --x) {
                if (dp[i][x] == -1) {
                    continue;
                }
                upd(i, x - 1, dp[i][x] + d);
            }
            for (int x = 0; x < max_x; ++x) {
                if (dp[i][x] == -1) {
                    continue;
                }
                long long cur = n / vals[i] + x - shift;
                if (cur < 0) {
                    continue;
                }
                ans = min(ans, dp[i][x] + mul(cur, d));
                for (int j = 0; j < 3; ++j) {
                    if (cur % val[j]) {
                        continue;
                    }
                    const int to = num[ids[0][i] + (j == 0)][ids[1][i] + (j == 1)][ids[2][i] + (j == 2)];
                    if (to == -1) {
                        continue;
                    }
                    long long tox = cur / val[j] + shift - n / vals[to];
                    if (0 <= tox && tox < max_x) {
                        upd(to, tox, dp[i][x] + a[j]);
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 14368
s1 = input()
s2 = input()
s1_len = len(s1)
s2_len = len(s2)
dp = [[i if j == 0 else j if i == 0 else None for j in range(s2_len+1)] for i in range(s1_len+1)]

for i in range(1, s1_len+1):
    for j in range(1, s2_len+1):
        n1 = dp[i-1][j-1] if s1[i-1] == s2[j-1] else dp[i-1][j-1]+1
        n2 = dp[i-1][j]+1
        n3 = dp[i][j-1]+1
        dp[i][j] = min(n1, n2, n3)

print(dp[s1_len][s2_len])

Measured memory_bytes: 44684
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
	ll N;
	cin >> N;
	vl L(N);
	FOR(i,0,N)cin >> L[i];
	sort(ALL(L));
	ll SUM = 0;
	FOR(i,0,N-1)SUM += L[i];
	Yes(SUM > L[N-1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
string S;
int main(){

    cin >> N >> S;
    int r = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == 'R'){
            r++;
        }
    }
    
    if(r > N - r){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vi=vector<int>;  using vs=vector<string>; using gi=greater<int>;
#define soao(c) sort((c).begin(),(c).end()) //昇順
#define sodo(c) sort((c).begin(),(c).end(),gi()) //降順
#define rev(c) reverse((c).begin(), (c).end())

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

  if(N<=M) cout<<"unsafe"<<endl;
  else cout<<"safe"<<endl;

}

Measured memory_bytes: 3592
# 足し合わせしすぎてるのでTLE
import sys
input = sys.stdin.readline

def main():
    H, W, K = map(int, input().split())
    grid = [list(map(int, list(input().strip()))) for _ in range(H)]

    # 折れる箇所全部で折った数が最大値
    ans = (H - 1) * (W - 1)

    # 横線で割るパターン全てについて縦線での降り方を考える
    for i in range(2 ** (H - 1)):
        snap = 0

        # 横線で折った後に縦線でみたときのwcの数を計算しておく
        hori_grid = [grid[0]]
        for j in range(H - 1):
            if ((i >> j) & 1):
                hori_grid.append(grid[j+1])
                snap += 1
            else:
                hori_grid[-1] = [a + b for a,b in zip(hori_grid[-1], grid[j+1])]

        # 先頭列のwcの数を保存
        wc_count = [hori_grid[y][0] for y in range(snap + 1)]

        # 最初の列で超えてる場合はスキップ
        if max(wc_count) > K:
            continue

        # 横方向にみていき、制限をこえたらその前の縦線で折る
        for x in range(1, W):
            now_wc_count = [hori_grid[y][x] for y in range(len(wc_count))]
            next_wc_count = [a+b for a,b in zip(wc_count, now_wc_count)]

            if max(next_wc_count) > K:
                # 超えてるのでおる。折った箇所より左側は無視
                snap += 1
                wc_count = now_wc_count
            else:
                # おらないので、wcの数に単純に加算したものをwcの数としてみる
                wc_count = next_wc_count

        ans = min(ans, snap)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N],sum,t;



int main()
{
	fast;
	cin>>ar[1]>>ar[2]>>ar[3];
	sort(ar+1,ar+4);
	if(ar[1]==ar[2] && ar[3]!=ar[2])
		return cout<<"Yes",0;
	if(ar[2]==ar[3] && ar[1]!=ar[2])
		return cout<<"Yes",0;
	cout<<"No";

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static class Move {
		int fx, fy, gx, gy;
		
		public Move(int fx, int fy, int gx, int gy) {
			this.fx = fx;
			this.fy = fy;
			this.gx = gx;
			this.gy = gy;
		}
		
		public String toString() {
			return this.fy + " " + this.fx + " " + this.gy + " " + this.gx;
		}
	}
	
	public static int[][] move_dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
	public static boolean in_range(int x, int y, int W, int H) {
		return 0 <= x && x < W && 0 <= y && y < H;
	}
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int T = sc.nextInt();
			
			int answer = Integer.MAX_VALUE;
			for(int i = 0; i < N; i++) {
				final int c = sc.nextInt();
				final int t = sc.nextInt();
				
				if(t <= T) {
					answer = Math.min(answer, c);
				}
			}
			
			
			if(answer == Integer.MAX_VALUE) {
				System.out.println("TLE");
			}else {
				System.out.println(answer);
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

int main(void){
    int n,t;
    cin >> n >> t;
    t /= 1000;

    for(int x=0;x<n+1;x++){
        for(int y=0;y<n+1-x;y++){
            for(int z=0;z<n+1-x-y;z++){
                if(10*x+5*y+z==t && x+y+z==n){
                    printf("%d %d %d\n",x,y,z);
                    return 0;
                } 
            }
        }
    }
    printf("-1 -1 -1\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF (1e9)
#define N_MAX 100
using namespace std;
const double EPS=1E-8;
typedef vector<double> vec;
typedef vector<vec> mat;

struct edge{
  int to,cap,rev;
  double cost;
};

int V;
vector<edge> G[N_MAX];
double dist[N_MAX];
int prevv[N_MAX],preve[N_MAX];

void add_edge(int from,int to,int cap,double cost){
  G[from].push_back((edge){to,cap,G[to].size(),cost});
  G[to].push_back((edge){from,0,G[from].size()-1,-cost});
}

double min_cost_flow(int s,int t,int f){
  double res=0;
  while(f>0){
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update=true;
    while(update){
      update=false;
      for(int v=0;v<V;v++){
	if(dist[v]==INF)continue;
	for(int i=0;i<G[v].size();i++){
	  edge &e=G[v][i];
	  if(e.cap>0&&dist[e.to]-(dist[v]+e.cost)>EPS){
	    dist[e.to]=dist[v]+e.cost;
	    prevv[e.to]=v;
	    preve[e.to]=i;
	    update=true;
	  }
	}
      }
    }
    if(dist[t]==INF)return -1;
    int d=f;
    for(int v=t;v!=s;v=prevv[v])
      d=min(d,G[prevv[v]][preve[v]].cap);
    f-=d;
    res+=d*dist[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap-=d;
      G[v][e.rev].cap+=d;
    }
  }
  return res;
}

vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j];
  for(int i=0;i<n;i++)B[i][n]=b[i];
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++)
      if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
    swap(B[i],B[pivot]);
    if(abs(B[i][i])<EPS)return vec();
    for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i];
    for(int j=0;j<n;j++){
      if(i!=j)
    for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
    }
  }
  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}

int main(){
  int T,N,s,t,F,M,d[N_MAX],f[N_MAX];
  cin>>T;
  while(T--){
    cin>>N>>s>>t>>F;
    V=N;
    vec b(N);
    mat A(N,vec(N,0));
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++)cin>>A[i][j];
      cin>>b[i];
    }
    vec r=gauss_jordan(A,b);
    for(int i=0;i<N;i++){
      cin>>M;
      for(int j=0;j<M;j++)cin>>d[j];
      for(int j=0;j<M;j++)cin>>f[j];
      for(int j=0;j<M;j++)
	add_edge(i,d[j],f[j],abs(r[i]-r[d[j]]));
    }
    double ans=min_cost_flow(s,t,F);
    if(ans!=-1)printf("%.8f\n",ans);
    else cout<<"impossible"<<endl;
    for(int i=0;i<N_MAX;i++)G[i].clear();
  }
  return 0;
}

Measured memory_bytes: 2076
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for(int i=0; i<N-2; i++) {
        string T = S.substr(i, 3);
        if(T == "ABC") {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# from typing import *
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def solve(N, A):
    for i in range(N):
        if A[i] == 0:
            print(0)
            return
    ans =1
    for i in range(N):
        if A[i] > math.pow(10,18):
            print(-1)
            return
        ans *= A[i]
        if ans > math.pow(10,18):
            print(-1)
            return
    print(ans)



def main():
    import sys
    tokens = iter(sys.stdin.read().split())
    N = int(next(tokens))
    A = [None for _ in range(N)]
    for i in range(N):
        A[i] = int(next(tokens))
    assert next(tokens, None) is None
    solve(N, A)

if __name__ == '__main__':
    main()

"""
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_b && sh testp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_b && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_b && sh submitp.sh
"""

Measured memory_bytes: 21964
#include <cstdio>
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int a, b;

int main() {
	while(1) {
		cin >> a >> b;
		if(a == 0 &&  b == 0) break;
		rep(i,a) {
			rep(j,b) {
				if(i == 0 || i == a - 1) cout << "#";
				else {
					if(j == 0 || j == b - 1) cout << "#";
					else cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

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

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	std::cout << 360 / gcd(360, n) << '\n';
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int maxn=1005;
int h,w;
int bx,by,ex,ey;
char s[maxn][maxn];
int mx[25]={-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2};
int my[25]={-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2};
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
typedef pair<int,int> pr;
bool vst[maxn*maxn];
int dis[maxn*maxn];
int prt[maxn*maxn];
bool met[maxn][maxn];
int bh(int x,int y){return (x-1)*w+y;}
int getf(int x){
	if(x==prt[x])return x;
	else return prt[x]=getf(prt[x]);
}
void dfs(int x,int y){
	met[x][y]=true;
	for(int i=0;i<4;++i){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx<=0||nx>h||ny<=0||ny>w||s[nx][ny]=='#')continue;
		if(met[nx][ny])continue;
		int f1=getf(bh(x,y)),f2=getf(bh(nx,ny));
		prt[f1]=f2;dfs(nx,ny);
	}	
}
vector<int> e[maxn*maxn];
map<int,bool> m[maxn*maxn];
#define INF 1e9
queue<int> Q;
void bfs(){
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)dis[bh(i,j)]=INF;
	int b=getf(bh(bx,by));
	dis[b]=0;Q.push(b);
	while(Q.size()){
		int x=Q.front();Q.pop();
		for(int i=0;i<e[x].size();i++){
			int y=e[x][i];
			if(dis[y]>dis[x]+1){
				dis[y]=dis[x]+1;
				Q.push(y);
			}
		}
	}
	int ed=getf(bh(ex,ey));
	if(dis[ed]==INF)puts("-1");
	else printf("%d\n",dis[ed]);
}
int main(){
	scanf("%d%d",&h,&w);
	scanf("%d%d",&bx,&by);
	scanf("%d%d",&ex,&ey);
	for(int i=1;i<=h;++i)scanf("%s",s[i]+1);
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)prt[bh(i,j)]=bh(i,j);
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)if(!met[i][j])dfs(i,j);
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)
			if(s[i][j]!='#'){
				for(int k=0;k<25;++k){
					int nx=i+mx[k],ny=j+my[k];
					if(nx<=0||nx>h||ny<=0||ny>w||s[nx][ny]=='#')continue;
					int f1=getf(bh(i,j)),f2=getf(bh(nx,ny));
					if(f1>f2)swap(f1,f2);
					if(f1==f2||m[f1][f2]==true)continue;
					m[f1][f2]=true;
					e[f1].push_back(f2);
					e[f2].push_back(f1);
				}
			}
	bfs();
	return 0;
}

Measured memory_bytes: 97812
import collections
import fractions
a, b = input().split()
A = int(a)
B = int(b)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


GCB = fractions.gcd(A, B)

C = collections.Counter(prime_factorize(GCB))

print(len(C) + 1)



Measured memory_bytes: 5056
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop") 
#define ll long long int
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b,c;
	cin>>a>>b>>c;

	ll k=b;
	if(a+b>=c){
		k=k+c;
	}
	else k+=(a+b+1);
	cout<<k;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

int a[100000];

int main(void) {
    int i, n, k;
    scanf("%d%d",&n,&k);
    REP (i,n) scanf("%d",&a[i]);
    ll sum = 0;
    REP (i,n) if (a[i] > 0) sum += a[i];

    ll s = 0;
    REP (i,k) {
        s += a[i];
        if (a[i] > 0) sum -= a[i];
    }
    ll ans = sum+max(0LL,s);
    REP (i,n-k) {
        s -= a[i];
        if (a[i] > 0) sum += a[i];
        s += a[i+k];
        if (a[i+k] > 0) sum -= a[i+k];
        ans = max(ans,sum+max(0LL,s));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b=0,c;
  cin>>a;
  c=a;
  while(true){
    if(c==0) break;
    b=b+c%10;
    c/=10;
  }
  if(a%b==0) cout<<"Yes";
  else cout<<"No";
  cout<<"\n";
  }

Measured memory_bytes: 256