akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
    int n;

    cin >> n;
    for(int i = 0; i < 26; i++){
        for(int j = 0; j < 16; j++){
            if(4 * i  + 7 * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC155
{
    class Program
    {
        static void Main(string[] args)
        {
            c();
        }

        public static void c()
        {
            long n = long.Parse(Console.ReadLine());
            var dic = new Dictionary<string, long>();
            long h = 0;
            for (long i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                if (dic.ContainsKey(s))
                {
                    dic[s]++;
                    if (h < dic[s])
                    { h = dic[s]; }
                }
                else
                {
                    dic[s] = 1;
                    if(h < dic[s])
                    { h = dic[s]; }
                }
            }
            var list = new List<string>();
            foreach(var x in dic.Keys)
            {
                if (dic[x] == h)
                    list.Add(x);
            }
            list.Sort(StringComparer.OrdinalIgnoreCase);
            foreach(var x in list)
            { Console.WriteLine(x); }
        }
    }
}


Measured memory_bytes: 41692
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long int> vec(N);
    for(int i=0; i<N; i++){
        cin >> vec[i];
    }
    std::sort(vec.begin(), vec.end());
    int c = 0;
    for(int i=0; i<N-1; i++){
        if(vec[i] == vec[i+1]){c++;}
    }
    if(c == 0){cout << "YES";}
    else{cout << "NO";}
}

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

size_t rankF2(vector<vector<long>>& a){ // calculate rank of matrix in F_2
    long n = a.size(), m = a[0].size();
    auto add = [&m](vector<long>& to, vector<long>& from){
        for(int i = 0; i < m; ++i)to[i] ^= from[i];
    };
    size_t now(0), ret(0);
    while(now < m && ret < n){
        size_t i(ret);
        for(; i < n; ++i)if(a[i][now])break;
        if(i == n){
            ++now;
            continue;
        }
        size_t j(i + 1);
        for(; j < n; ++j)if(a[j][now])add(a[j], a[i]);
        swap(a[ret], a[i]);
        ++ret;
    }
    return ret;
}

int main(){
    constexpr long m = 998244353;
    auto modpow = [&m](long n){
        long r = 1, p = 2;
        while(n){
            if(n & 1){
                r *= p;
                r %= m;
            }
            p *= p;
            p %= m;
            n >>= 1;
        }
        return r;
    };

    long N, M;
    cin >> N >> M;
    bool f = false;
    if(N > M && (f = true))swap(N, M);

    vector<vector<long>> a(N, vector<long>(M));
    if(f)for(int i = 0; i < M; ++i)for(int j = 0; j < N; ++j)scanf("%ld", &a[j][i]);
    else for(auto& i : a)for(auto &j : i)scanf("%ld", &j);

    auto r = rankF2(a);
    cout << modpow(N + M - r - 1) * (modpow(r) - 1) % m << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;

vector<int> primes;
map<int, int> factors;

void erathosthenes(int n) {
    bool primeFlags[n+1];//boolでふるいを用意する。素数であればtrueであるとする
    for (int i = 0; i <= n; i++) primeFlags[i] = true;//ふるいをリセット
    primeFlags[0] = primeFlags[1] = false;//0と1は素数ではないのでふるい落とす(=falseにする)
    vector<int> sqrtprimes;//ルートnまでの素数を入れておくための配列
    for (int i = 2; i*i <= n; i++) {
        bool mod0 = false;
        for (int j = 2; j*j <= i; j++) {
            if (i%j == 0) mod0 = true;
        }
        if (!mod0) sqrtprimes.push_back(i);
    }
    for (int i = 0; i < sqrtprimes.size(); i++) {
        for (int j = 2; j <= n; j++) {
            if (j%sqrtprimes[i] == 0) primeFlags[j] = false;
        }
    }
    for (int i = 0; i < sqrtprimes.size(); i++) primeFlags[sqrtprimes[i]] = true;
    for (int i = 1; i <= n; i++) if (primeFlags[i]) primes.push_back(i);
    return;
}

void factoring(int n) {
    for (int i = 0; i < primes.size(); ++i) {
        while(n%primes[i] == 0){
            factors[primes[i]]++;
            n /= primes[i];
        }
    }
}

void factorial(int n) {
    erathosthenes(n);
    for (int i = 2; i <= n; ++i) {
        factoring(i);
    }
}

//---------以上ライブラリ--------//----------以下debug用main関数----------//


int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    factorial(n);
    ll ans = 1;
    ll mod = 1000000007;
    for (auto x : factors) {
        ans = ans*(x.second+1)%mod;
    }
    cout << ans << std::endl;
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  cout << n / 2 + n % 2 << endl;
  return 0;
}


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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n)cin>>a[i];
	SORT(a);
	
	int plus_index = n-1;
	rep(i,n){
		if(a[i] >= 0){
			plus_index = i;
			break;
		}
	}
	plus_index = max(1,plus_index);
	//plus_index以降のものは+にする.ソレより以前は-にする。
	ll now = a[plus_index - 1];
	vector<P> ans(0);
	for(int i = plus_index; i < n -1; i++){
		ans.push_back({now,a[i]});
		now -= a[i];
	}
	// aから残りを引いていく。
	for(int i = 0; i < plus_index - 1; i++){
		ans.push_back({a[n-1],a[i]});
		a[n-1] -= a[i];
	}
	ans.push_back({a[n-1],now});
	a[n-1] -= now;
	cout << a[n-1] << endl;
	for(auto x : ans){
		cout << x.first << " " << x.second << endl;
	}

}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,b[100],a[100][100];
  cin>>n>>m;
  for(int i=0;i<n;++i)
    for(int j=0;j<m;++j) cin>>a[i][j];
  for(int i=0;i<m;++i) cin>>b[i];
  for(int i=0;i<n;++i){
    int sum=0;
    for(int j=0;j<m;++j)
      sum+=a[i][j]*b[j];
    cout<<sum<<endl;
  }
  return 0;
}




Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		loop: while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			count = 0;
			visited = new boolean[h][w];
			sx = -1;
			sy = -1;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int now = scanner.nextInt();
					if (now == 0) {
						count++;
						if (sx == -1) {
							sy = i;
							sx = j;
						}
					} else {
						visited[i][j] = true;
					}
				}
			}
			if (count % 2 == 1 || count == 0) {
				System.out.println("No");
				continue;
			}
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (visited[i][j])
						continue;
					int count = 0;
					for (int k = 0; k < 4; k++) {
						int x = j + vx[k];
						int y = i + vy[k];
						if (!isOK(x, y))
							continue;
						if (!visited[y][x])
							count++;
					}
					if (count < 2) {
						System.out.println("No");
						continue loop;
					}
				}
			}

			System.out.println(dfs(sx, sy, 0) ? "Yes" : "No");
		}

	}

	private boolean dfs(int x, int y, int deep) {
		if (count - deep < Math.abs(x - sx) + Math.abs(y - sy))
			return false;

		for (int i = 0; i < 4; i++) {
			int nx = x + vx[i];
			int ny = y + vy[i];
			if (!isOK(nx, ny))
				continue;
			if (ny == sy && nx == sx && deep + 1 == count)
				return true;
			if (visited[ny][nx])
				continue;
			boolean res = check(nx, ny);
			if (!res)
				continue;
			visited[ny][nx] = true;
			if (dfs(nx, ny, deep + 1))
				return true;
			visited[ny][nx] = false;
		}
		return false;

	}

	private boolean check(int x, int y) {
		loop: for (int i = 4; i < vx.length; i++) {
			int nx = x + vx[i];
			int ny = y + vy[i];
			if (!isOK(nx, ny))
				continue;
			if (nx == sx && ny == sy)
				continue;
			if (visited[ny][nx])
				continue;
			int count = 0;
			for (int j = 0; j < 4; j++) {
				int nnx = nx + vx[j];
				int nny = ny + vy[j];
				if (!isOK(nnx, nny))
					continue;
				if (visited[nny][nnx])
					continue;
				count++;
				if (count == 2)
					continue loop;
			}
			return false;
		}
		return true;
	}

	private boolean isOK(int x, int y) {
		if (0 <= x && x < w && 0 <= y && y < h)
			return true;
		return false;
	}

	boolean[][] visited;
	boolean ans;
	int count, w, h, sx, sy;
	int[] vx = { 0, 1, 0, -1, 1, 1, -1, -1 };
	int[] vy = { -1, 0, 1, 0, -1, 1, 1, -1 };
}

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

int main(void){
    vector<string> str;
    int n, i, j;
    string s;
    map<string, int> mp;

    cin >> n;
    rep(i, n){
        cin >> s;
        str.push_back(s);
    }

    rep(i, n){
        sort(str[i].begin(), str[i].end());
        mp[str[i]]++;
    }
    
    ll count = 0;
    for(auto &p : mp){
        int s = p.second;
        count += (ll)s*(s-1)/2;
    }

    cout << count << endl;
}


Measured memory_bytes: 18164
from collections import Counter
n=int(input())
A=[0]+list(map(int,input().split()))
for i in range(1,n+1):
    A[i] +=A[i-1]

ans=0
for m in Counter(A).values():
    if m==1:continue
    else:
        ans +=(m*(m-1))//2

print(ans)

Measured memory_bytes: 37248
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>

using namespace std;

int main(){
    int n, a;
    cin >> n;
    set<int> card;
    for(int i = 0; i < n; i++){
        cin >> a;
        card.insert(a);
    }

    cout << (card.size() % 2 == 0 ? card.size() - 1 : card.size()) << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

vector<int> A;
int n,m,q;
vector<int> a(60),b(60),c(60),d(60);
int ans=0;

void dfs(int x){
    A.push_back(x);
    if(A.size()==n){
        int tmp=0;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i]) tmp+=d[i];
        }
        ans=max(ans,tmp);
        return;
    }
    for(int i=x;i<=m;i++){
        dfs(i);
        A.pop_back();
    }
}

int main(){
    
    cin>>n>>m>>q;
    
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;
        b[i]--;
    }

    
    for(int i=1;i<=m;i++){
        A.clear();
        dfs(i);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3560
#include<iostream>
#include<algorithm>
#include<queue>
 
using namespace std;
 
const int MAX = 260;
bool come[MAX],goal[MAX];
int M,n,d[MAX];
 
void print(){
 
  for(int i = 0; i <= n; i++) cout << come[i] << " ";
  cout << endl;
  for(int i = 0; i <= n; i++) cout << goal[i] << " ";
  cout << endl;
}
 
void init(){
  fill(come,come+MAX,false);
  fill(goal,goal+MAX,false);
  fill(d,d+MAX,0);
}
 
int move(int now, int num){
  int nex = now+num;
  if(nex > n) return -1;
  nex += d[nex];
  if(nex > n) return -1;
  if(nex < 0) return 0;
  return nex;
}
 
void make_come(){
  come[0] = true;
  priority_queue<int,vector<int>,greater<int> > Q;
  Q.push(0);
  while(!Q.empty()){
    int now = Q.top();
    Q.pop();
 
    for(int i = 1; i <= M; i++){
      int nex = move(now,i);
      if(nex == -1) goal[now] = true;
      else if(!come[nex] && nex <= n){
        come[nex] = true;
        Q.push(nex);
      }
    }
  }
}
 
void make_goal(){
 
  while(1){
    bool update = false;
 
    for(int i = n; i >= 0; i--){
      if(!come[i] || goal[i]) continue;
       
      for(int j = 1; j <= M; j++){
        int nex = move(i,j);
        if(nex == -1){
          goal[i] = true;
          update = true;
        }else if(goal[nex]){
          goal[i] = true;
          update = true;
        } 
      }
    }
    if(!update) break;
  }
}
 
 
bool solve(){
 
  make_come();
  make_goal();
 
  for(int i = 0; i <= n; i++)
    if(come[i] && !goal[i]) return false; 
  return true;
}
 
int main(){
 
  while(cin >> M && M){
    init();
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> d[i];
    if(solve()) cout << "OK" << endl;
    else cout << "NG" << endl;
    //print();
  }
   
  return 0;
}

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


            
int main(){
    ll h,n;cin>>h>>n;
    ll a[n+1],b[n+1];rep(i,1,n)cin>>a[i]>>b[i];
    ll dp[n+1][20010];
    rep(i,0,20000){
        if(i==0){
            dp[0][0]=0;
        }else{
            dp[0][i]=inf;
        }
    }
    rep(i,1,n)rep(j,0,20000){
        if(j-a[i]>=0){
            if(dp[i][j-a[i]]==inf){
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=min(dp[i][j-a[i]]+b[i],dp[i-1][j]);
            }
        }else{
            dp[i][j]=dp[i-1][j];
        }
    }
    ll ans=inf;
    rep(i,h,20000){
        ans=min(dp[n][i],ans);
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 156800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,t;cin >> n >> t;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	ll ans = t;
	rep(i,n - 1){
		ans += min(a.at(i + 1) - a.at(i), t);
	}
	cout << ans << endl;
}


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

using namespace std;

struct Dsu {
    int n;
    vector<int> p;
    
    Dsu(int _n) { n = _n; p.resize(n); init(); }
    inline void init() {
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
    }
    inline int find(int x) {
        return p[x] == x ? x: p[x] = find(p[x]);
    }
    inline bool join(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        p[y] = x; return true;
    }
    inline bool check(int x, int y) {
        return find(x) == find(y);
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n+1);
    vector<int> d(n+1, 0);
    while (m--) {
        int u, v;
        cin >> u >> v;
        d[u]++; d[v]++;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    auto gg = [](){
        cout << "No" << "\n";
        exit(0);
    };
    auto wp = [](){
        cout << "Yes" << "\n";
        exit(0);
    };
    int ge6 = 0;
    int eq4 = 0;
    int A = -1;
    for (int i = 1; i <= n; i++) {
        if (d[i] & 1) gg();
        if (d[i] >= 6) ge6++;
        if (d[i] == 4) eq4++, A = i;
    }
    if (ge6) wp();
    if (eq4 >= 3) wp();
    if (eq4 <= 1) gg();
    Dsu dsu(n+1);
    for (int i = 1; i <= n; i++) {
        if (i != A) {
            for (int j: g[i]) {
                if (j != A && j < i) {
                    if (!dsu.join(i, j)) wp();
                }
            }
        }
    }
    gg();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

const ll MAX = 510000;
const ll MOD = 1e9 + 7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll COM(ll n, ll k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll powMod(ll x, ll k) {
  if (k == 0) return 1;
  if (k % 2 == 0)
    return powMod(x * x % MOD, k / 2);
  else
    return x * powMod(x, k - 1) % MOD;
}

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  COMinit();
  ll ret = 0;
  for (ll d = 1; d <= N - 1; d++) {
    ret = (ret + d * (N - d) * M * M % MOD * COM(N * M - 2, K - 2)) % MOD;
  }
  for (ll d = 1; d <= M - 1; d++) {
    ret = (ret + d * (M - d) * N * N % MOD * COM(N * M - 2, K - 2)) % MOD;
  }
  cout << ret << endl;
}

Measured memory_bytes: 12160
Str = input()
atgc = ['A', 'T', 'G', 'C']
max_cnt = 0
cnt = 0
for s in Str:
    if s in atgc:
        cnt += 1
        if max_cnt < cnt:
            max_cnt = cnt
    else:
        cnt = 0
print(max_cnt)


Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    double ans = 0;
    int ansmass = min(A, B);
    int anssugar = 0;
    ansmass *= 100;
    rep(i, 30) {
        int water = 0;
        int sugar = 0;
        rep(j, 30) {
            water = 100 * (A*i + B*j);
            if (water == 0 || water > F) break;
            rep(k, 100) {
                rep(l, 100) {
                    sugar = C*k + D*l;
                    if (water + sugar <= F && (E * water/100) >= sugar) {
                        //dump(ans);
                        //dump(water);
                        //dump(sugar);
                        if (ans < 100.0*sugar/(water + sugar)){
                            ans = 100.0*sugar/(water + sugar);
                            ansmass = water + sugar;
                            anssugar = sugar;
                        }
                    }
                }
            }
        }
    }
    cout << ansmass << " " << anssugar <<endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F(i,a,n) for(int i=a;i<n;i++)
#define mod 1000000007 
#define pb push_back
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int w=1;
	// cin>>w;
	while(w--){
		long long n;
		cin>>n;
		vector<ll> v(2005,0);
		v[0]=1;
		v[3]=1;
		v[4]=1;
		v[5]=1;
		F(i,6,n+1){
			F(j,3,i+1){
				if(i-j>=0)
				v[i]=(v[i]%mod+v[i-j]%mod)%mod;
			}
		}
		cout<<v[n];
	}
	return 0;
}

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

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

  int x; cin >> x;

  int ans = 1;
  for(int i = 2; i <= x; i++) {
    int tmp = i*i;
    while(true) {
      if(tmp > x) break;
      ans = max(ans, tmp);
      tmp *= i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <string>
#include <vector>
using namespace std;
 
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define reps(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
 
string s;
long long int n, a, b;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> a >> b;
    cout << min(n*a, b) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int MAXN=200010, TS=1000010, SGM=26;

ll n, m, k, u, v, x, y, t, a, b, ans;
string S[MAXN];
int TR[TS][SGM], cnt[TS], ts;
int last[26];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++){
		cin>>S[i];
		reverse(all(S[i]));
		int v=0;
		for (char ch:S[i]){
			if (!TR[v][ch-'a']) TR[v][ch-'a']=++ts;
			v=TR[v][ch-'a'];
		}
		cnt[v]++;
	}
	for (int i=1; i<=n; i++){
		memset(last, -1, sizeof(last));
		int sz=S[i].size();
		for (int j=0; j<sz; j++) last[S[i][j]-'a']=j;
		int v=0;
		for (int j=0; j<sz; j++){
			for (int k=0; k<26; k++) if (last[k]>=j){
				ans+=cnt[TR[v][k]];
			}
			v=TR[v][S[i][j]-'a'];
			if (!v) break ;
		}
	}
	cout<<ans-n<<"\n";
	
	return 0;
}


Measured memory_bytes: 115396
import sys
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    f = lambda h, m, s: 3600*h + 60*m + s
    H, h, m, s = map(int, readline().split())
    if H == 0:
        return False
    d0 = f(h, m, s)
    M = f(H, 0, 0)
    res = []
    for h0 in range(H):
        for m0 in range(60):
            p = 3600*h0 + 60*m0 + 60*H*m0; q = 119*H-1
            for d in [-3600*H, 0, 3600*H]:
                p1 = p + d; q1 = q
                g = gcd(p1, q); p1 //= g; q1 //= g
                if 0 <= p1 < 60*q1:
                    if H*(60*m0*q1 + p1) != q1*(3600*h0 + 60*m0) + p1:
                        res.append((f(h0, m0, 0) + p1/q1, h0, m0, p1, q1))
    res.sort(key = lambda x: (x[0] - d0) % M)
    _, h, m, p, q = res[0]
    write("%d %d %d %d\n" % (h, m, p, q))
    return True
while solve():
    ...


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

int main()
{
    int n,t,l=0,c,i,ans=0;
    cin>>n>>t;
    for(i=0;i<n;i++)
    {
        scanf("%d",&c);
        if(c-l<t)ans+=c-l;
        else ans+=t;
        l=c;
    }
    cout << ans+t << endl;
    return 0;
}


Measured memory_bytes: 256
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define Iter(c) __typeof__((c).begin())
#define foreach(i,c) for(Iter(c) i = (c).begin();i != (c).end();++i)
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};


int main(){
  int m,n;

  while(true)
    {
      cin >> m;
      if(!m)break;
      cin >> n;
      int cnt = 0;
      for(int i=1;i<=n;i*=2)
	{
	  for(int j=1;i*j<=n;j*=3)
	    {
	      for(int k=1;k*i*j<=n;k*=5)
		{
		  if(i*j*k >= m)
		    cnt++;
		}
	    }
	}
      cout << cnt << endl;
    }

return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    long dp[][];
    long INF = Long.MAX_VALUE;
    int ns[];
    int n;

    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        ns = new int[n];
        for (int i = 0; i < n; i++) {
            ns[i] = sc.nextInt();
        }
        dp = new long[21][n];
        for (int i = 0; i < 21; i++)
            Arrays.fill(dp[i], -1);
        dp[0][0] = solve(ns[0], 1);
        System.out.println(dp[0][0]);
    }

    long solve(int sum, int i) {
        long res = 0;
        if (sum > 20 || sum < 0)
            return 0;
        else if (dp[sum][i] >= 0) {
            return dp[sum][i];
        } else if (i == n - 1) {
            if (sum == ns[i]) {
                res = 1;
            } else
                res = 0;
        } else {
            res = solve(sum + ns[i], i + 1) + solve(sum - ns[i], i + 1);
        }
        return dp[sum][i] = res;
    }

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

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

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long x;
	cin >> x;
	long long cur = 100;
	int ans = 0;
	while (cur < x) {
		cur += cur / 100;
		ans++;
	}
	cout << ans;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


int main() {
    int n; cin >> n;
    ll a[n][3];
    cin >> a[0][0] >> a[0][1] >> a[0][2];
    for(int i = 1;i < n;i++){
        int x,y,z; cin >> x >> y >> z;
        a[i][0] = max(a[i-1][1]+x,a[i-1][2]+x);
        a[i][1] = max(a[i-1][0]+y,a[i-1][2]+y);
        a[i][2] = max(a[i-1][0]+z,a[i-1][1]+z);
    }
    ll ans = 0;
    for(int i = 0;i < 3;i++){
        ans = max(ans,a[n-1][i]);
    }
    cout << ans;
}


Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int[] d = new int[n];

		for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}

		int m = sc.nextInt();
		int[] t = new int[m];

		for (int i = 0; i < m; i++) {
			t[i] = sc.nextInt();
		}

		Arrays.sort(d);
		Arrays.sort(t);

		boolean isCpl = true;
		int idxD = 0;
		int idxT = 0;
		while (idxT < m) {
			if (idxD == n) {
				isCpl = false;
				break;
			}

			if (t[idxT] == d[idxD]) {
				idxT++;
				idxD++;
			} else {
				idxD++;
			}
		}

		System.out.println(isCpl ? "YES" : "NO");

		sc.close();
	}

}


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

int main(){
  int h,n,ttl=0;cin>>h>>n;
  REP(i,n){
    int tmp;cin>>tmp;
    ttl+=tmp;
  }
  cout<<(ttl>=h?"Yes":"No");
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

int main(){
unsigned long int a,b,s,i;
while(cin>>a>>b)
{
    s=a+b;
    i=0;
    do
    {
      s/=10;
      i++;
    }
    while(s!=0);
    cout<<i<<"\n";
}
    return 0;
}

Measured memory_bytes: 1156
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する
const int mod = 1000000007;


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

    bool prime[1001];
    REP(i, 0, 1001) {
        prime[i] = true;
    }
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i <= 1000; i++) {
        if (prime[i]) {
            for (int j = i * 2; j <= 1000; j += i) {
                prime[j] = false;
            }
        }
    }
    vector<int> primes;
    REP(i,0,1001){
        if(prime[i]) primes.push_back(i);
    }

    vector<int> pows(primes.size());
    for(int i = 0; i < primes.size(); i++){
        pows[i] = 1;
        for(int j = 1; (N/(int)pow(primes[i],j)) > 0; j++){
            pows[i] += N/pow(primes[i],j);
        }
    }

    ll ret = 1;
    REP(i,0,primes.size()){
        ret = ((ll)ret * (ll)pows[i]) % (ll)mod;
    }

    cout << ret << endl;


    return 0;
}


Measured memory_bytes: 256
/**
 * @Author:      K C-L
 * @DateTime:    2018-06-03 20:00:40
 * @Description: 
 */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef stringstream strstm;
#define fi first
#define se second
#define INF 0X3f3f3f3f
#define SZ(x) ((int)(x).size())
#define pb push_back
#define PI acos(-1.0)
#define E 2.718281829459
#define lowbit(x) (x & (-x))
#define DBG(x) cout << (x) <<  << endl;
#define MST(a,b) memset(a,b,sizeof(a));
#define _for(i,a,b) for(int i = (a); i < (b); ++i)
#define _rep(i,a,b) for(int i = (a); i <= (b); ++i)

int len,ans,res,n;

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

	string str; while(cin >> n >>  str){
		len = str.length();
		res = -INF;
		_rep(i,0,len-1){
			ans = 0;
			set<char> st;
			_rep(j,0,i) st.insert(str[j]);
			set<char> st2;
			_rep(j,i+1,len-1) st2.insert(str[j]);

			for(auto j : st){
				if(st2.count(j)) ans++;
			}
			res = max(ans,res);
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n,j=1,sum=0;
    cin>>n;
    int c=0;
    map<string,int> count;
    vector<string> in;
    for(int i=0;i<n;i++){
        string x;
        cin>>x;
        sort(x.begin(),x.end());
        in.push_back(x);
    }
    for(int i=0;i<n;i++){
        count[in[i]]++;
    }
    map<string,int>:: iterator it;
    for(it = count.begin();it!=count.end();it++){
        int y=it->second;
        sum+=y*(y-1)/2;
    }
    cout<<sum;
}

Measured memory_bytes: 12020
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) throws Exception {
	    Scanner sc = new Scanner(System.in);   
	    
	    int N = sc.nextInt();
	    
	    if (N == 1) {
	    	System.out.println("Hello World");
	    } else {
	    	System.out.println(sc.nextInt() + sc.nextInt());
	    }
	}    
}	

Measured memory_bytes: 22868
//JSD
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n;
	cin>>n;
	int h[n+1];
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	//calculating answer using iterative dp
	int dp[n+2]={0};
	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++){
		dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
	}
	cout<<dp[n];
	return 0;
}

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

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

typedef long long int ll;

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

using namespace std;

int main()
{
    int N, L;
    cin >> N >> L;
    int ans = 0;
    int min = 999999;
    for (int i = 0; i < N; i++) {
        int tmp = L + i;
        ans += tmp;
        if (abs(min) > abs(tmp)) {
            min = tmp;
        }
    }
    cout << ans - min << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

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

int main(){
  int n, result = 0;
  cin >> n;
  vector<int> a(n);
  
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  
  for(int i = 1; i < n-1; i++){
    if( (a[i-1] < a[i] && a[i] < a[i+1]) || (a[i-1] >  a[i] && a[i+1] < a[i] ) ){
      result++;
    }
  }
  
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int i,n=s.size(),total=0;
	for(i=0;i<n/2;i++){
		if(s[i]!=s[n-i-1]) total++;
	}
	cout<<total<<endl;
	return 0;
} 

Measured memory_bytes: 256
n, m = map(int, input().split())
sc_li = [list(map(int,input().split())) for _ in range(m)]
sc = []
i_s = ""

for i in range(1000):
    flag = True
    i_s= str(i)
    if len(i_s) != n:
        continue
    for j in range(m):
        sc = sc_li[j]
        s = sc[0]
        c = sc[1]
        if int(i_s[s-1]) != c:
            flag = False
    if flag:
        print(i_s)
        exit(0)

print(-1)

Measured memory_bytes: 3064
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    # N = int(input())
    # QUERYS = [input().split() for _ in range(Q)]
    H1, M1, H2, M2, K = [int(a) for a in input().split()]
    # A = [int(a) for a in input().split()]
    # T1, T2, T3 = [int(a) for a in input().split()]
    s = H1*60+M1
    e = H2*60+M2

    print(e-s-K)


if __name__ == "__main__":
    main()


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

using namespace std;

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    /*整数bのもつcでもdでも割り切れない数の量 */
    long long x, y, z, cb;
    x = b / c;
    y = b / d;
    z = b / (c*d/__gcd(c,d));
    cb = b - x - y + z;

    /*整数a-1のもつcでもdでも割り切れない数の量 */
    a = a - 1;
    long long h, i, j, ca;
    h = a / c;
    i = a / d;
    j = a / (c*d/__gcd(c,d));
    ca = a - h - i + j;

    long long ans;
    ans = cb- ca;
    cout << ans << endl;
 



    return 0;
}

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

int main(){
  int h,w;
  cin>>h>>w;
  string grid[h];
  for(int i=0;i<h;i++){
    cin>>grid[i];
  }
  int vec[h][w]={};
  int vecb[h][w]={};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(grid[i][j]=='#')continue;
      if(j>0&&grid[i][j-1]=='.'){
        vec[i][j]=vec[i][j-1];
        continue;
      }
      int x=0;
      int now=j;
      while(now<w&&grid[i][now]=='.'){
        x++;
        now++;
      }
      vec[i][j]=x;
    }
  }
  
  
  for(int j=0;j<w;j++){
    for(int i=0;i<h;i++){
      if(grid[i][j]=='#')continue;
      if(i>0&&grid[i-1][j]=='.'){
        vecb[i][j]=vecb[i-1][j];
        continue;
      }
      int x=0;
      int now=i;
      while(now<h&&grid[now][j]=='.'){
        x++;
        now++;
      }
      vecb[i][j]=x;
    }
  }
  
  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans=max(ans,vec[i][j]+vecb[i][j]-1);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 42456
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	int n;
  cin >> n;
  long long int a[n];
  for(int i=0;i<n;i++)
    	cin >> a[i];
  long long int stool=0;
  for(int i=1;i<n;i++)
    if(a[i]<a[i-1]){
      stool+=a[i-1]-a[i];
      a[i]=a[i-1];}
  cout << stool;
  	
    return 0;
}

Measured memory_bytes: 5188
import java.util.Scanner;
import java.util.Arrays;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String B = sc.next();
        char[] a = A.toCharArray();
        char[] b = B.toCharArray();
        if (A.length() > B.length()) {
            System.out.println("GREATER");
            return;
        } else if (A.length() < B.length()) {
            System.out.println("LESS");
            return;
        }
        for (int i = 0; i < A.length(); i++) {
            if ((int) a[i] > (int) b[i]) {
                System.out.println("GREATER");
                return;
            } else if ((int) a[i] < (int) b[i]) {
                System.out.println("LESS");
                return;
            }
            if (i == A.length() - 1) {
                System.out.println("EQUAL");
            }
        }
    }
}

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

int main() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if(s.at(i) == t.at(i)) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
object Main {
	def main(args: Array[String]) {
		val in = readLine.split(" ").map(_.toInt)
		val a = in(0)
		val b = in(1)
		if(a > b) {
			println("a > b")
		}
		else if(a == b) {
			println("a == b")
		}
		else if(a < b) {
			println("a < b")
		}
	}
}

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

int main(){
  ll k, n; cin >> k >> n;
  vector<ll> a(n);
  for(int i=0; i<n; ++i) cin >> a[i];
  
  ll maxdis;
  for(int i=0; i<n; ++i){
    ll dis = a[i+1] - a[i];
    if(i == n-1) dis = a[n-1] - a[0];
    if(dis > k / 2) dis = k - dis;
    if(i == 0 || maxdis < dis) maxdis = dis;
  }
  cout << k - maxdis << endl;
  return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    while(cin>>n)
    {
        long long a[n+5],b[n+5];
        for(int i=1; i<=n; i++)
        {
            cin>>a[i];
            cin>>b[i];
        }
        long long  ans=0;
        for(int i=n; i>0; i--)
        {
            long long  temp = 0;
                    temp = (b[i]-((a[i]+ans)%b[i]))%b[i];
                    ans += temp;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define N 101

int main(){
  int n = 0, u = 0, k = 0 ,v = 0;
  int g[N][N] = {0}; // 1-origin
  int i, j;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%d%d", &u ,&k);
    for( j = 1 ; j <= k ; j++ ){
      scanf("%d" ,&v );
      g[u][v] = 1;
    }
  }

  for( u=1 ; u <= n ; u ++ ){
    for( v=1 ; v <= n ; v++ ){
      printf("%d" ,g[u][v] );
      if( v != n ){
	printf(" ");
      }
    }
    printf("\n");
  }
  return 0; // Don't forget return 0
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
const int maxn=2010;
typedef long long ll;
typedef pair<int, int>pii;
int n, k, q;
int arr[maxn], id[maxn], ans=INT_MAX;
bool cmp(int a, int b)
{
    return arr[a]<arr[b];
}
void test(int val)
{
    vector<int>vals;
    queue<int>Q;
    for(int i=1; i<=n+1; i++)
    {
        if(arr[i]<val)
        {
            bool good=(sz(Q)>=k);
            vector<int>temp;
            while(sz(Q))
            {
                if(good)temp.pb(Q.front());
                Q.pop();
            }
            if(good)
            {
                sort(all(temp));
                int SZ=sz(temp);
                for(int i=0; i<(SZ-k+1); i++)vals.pb(temp[i]);
            }
        }
        else Q.push(arr[i]);
    }
    if(sz(vals)>=q)
    {
        sort(all(vals));
        ans=min(ans, vals[q-1]-vals[0]);
    }
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n>>k>>q;
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i];
        id[i]=i;
    }
    sort(id+1, id+n+1, cmp);
    for(int i=1; i<=n; i++)
        test(arr[id[i]]);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;
	cin>>S;
	int scnt = 0;
	int tcnt = 0;
	rep(i,S.size()){
		if(S[i] == 'S')scnt++;
		else{
			if(scnt>0){
				tcnt++;
				scnt--;
			}
		}
	}
	int ans = S.size() - 2*tcnt;
	
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
using Graph = vector<VE>;

int cnt[65][2];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, n)rep(j, 60) {
		cnt[j][(bool)(a[i] & (1LL << j))]++;
	}
	int ans = 0;
	for (int i = 59; i >= 0; i--) {
		ans *= 2; ans %= MOD;
		ans += cnt[i][0] * cnt[i][1] % MOD; ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	int count = 0;
	for (int i = 0; i < s.size()/2; i++) {
		if (s[i] != s[s.size()-i-1])
			count++;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3536
import Data.List
import Data.Char
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as BS8

main :: IO ()
main = do
    a <- replicateM 3 $ unfoldr (BS8.readInteger . BS8.dropWhile isSpace) <$> BS8.getLine
    n <- fst . fromJust . BS8.readInteger <$> BS8.getLine
    b <- unfoldr (BS8.readInteger . BS8.dropWhile isSpace) <$> BS8.getContents
    
    let l = map (map (\i -> elem i b)) a

    putStrLn $ if (any id $ map (all id) l) || (any id $ map (all id) $ transpose l) || (all id [(l !! x) !! x | x <- [0..2]]) || (all id [(l !! x) !! (2 - x) | x <- [0..2]]) then "Yes" else "No"


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

int main() {
  int N;
  cin >> N;
  
  int count = 0;
  int ans = 0;
  for(int i = 1; i <= N; i+=2){
   for (int j = 1; j <= N; j++){
    if( i % j == 0 ) count++;
   }
    if( count == 8 ) ans++;
    count = 0;
 }
  cout << ans << endl;
}


Measured memory_bytes: 256