akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] c=new int[n-1];
    int[] s=new int[n-1];
    int[] f=new int[n-1];
    for(int i=0;i<n-1;i++){
      c[i]=sc.nextInt();
      s[i]=sc.nextInt();
      f[i]=sc.nextInt();
    }
    for(int i=0;i<n;i++){
      long time=0;
      for(int j=i;j<n-1;j++){
        if(time<=s[j]){
          time=s[j];
        }else{
          time=(time+f[j]-1)/f[j]*f[j];
        }
        time=time+c[j];
      }
      System.out.println(time);
    }
  }
}

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

int main() {
    int A, B;
    cin >> A >> B;
    int value = -1, a, b;
    for (int i = 1; i <= 10000; i++) {
        int v8 = i * 0.08, v10 = i * 0.1;
        if (v8 == A && v10 == B) {
            value = i;
            break;
        }
    }
    cout << value << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
all_val = sum(A)
left = all_val // 2
right = (all_val+1) // 2
sub_sum = 0
for val in A:
    old = sub_sum
    sub_sum += val
    if sub_sum >= left:
        ans = 2 * min(abs(sub_sum - left),abs(left - old) , abs(sub_sum - right), abs(right - old))
        if ans % 2 != all_val % 2:
                ans += 1
        print(ans)
        break
             


Measured memory_bytes: 26220
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

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

int main() {
	ll N, K; cin >> N >> K;
	map<ll, ll> mp;
	rep(i, 0, N) {
		ll a, b; cin >> a >> b;
		mp[a] += b;
	}

	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		K -= it->second;
		if (K <= 0) {
			cout << it->first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>

int main(){
  int n,i;
  scanf("%d", &n);
  int res = 0;
  for(i=0;i<n;i++){
    int l,r;
    scanf("%d %d", &l,&r);
    res += (r-l+1);
  }
  printf("%d\n", res);
  return 0;
}


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

int main()
{
	int a, b, c;
	
	scanf("%d%d%d", &a, &b, &c);
	if ((a * 100 + b * 10 + c) % 4) {
		puts("NO");
	} else {
		puts("YES");
	}
}

Measured memory_bytes: 256
P = [1 for i in range(1000000)]
# 素数リスト(0 ~)

P[0] = 0
P[1] = 0

for i in range(2, 1000000) :
    for j in range(2, 1000000 // i) :
        P[i * j] = 0
        # 倍数はフラグを0に
        
while True :
    a, d, n = map(int, input().split())
    
    if a == 0 :
        break
    
    else :
        A = [i for i in range(a, 1000000, d)]
        cnt = 0
        
        for i in range(len(A)) :
            if P[A[i]] == 1 :
                cnt += 1
            
            if cnt == n :
                print(A[i])
                break
        
        
        



Measured memory_bytes: 57660
N = int(input())
L = []
L2 = []
for i in range(N) :
    l = int(input())
    L.append(l)
    L2.append(l)
L = sorted(L)
L2 = sorted(L2)
ANS = []
for i in range(2) :
    ans = 0
    turn = i
    flag = 0
    B = []
    if i == 0 :
        while len(L) != 0 :
            if len(L) == 1 :
                r = L[0]
                L.pop(0)
            else :
                if turn == 0 :
                    p = L[-1]
                    if flag != 0 :
                        ans += abs(p-q)
                    else :
                        B.append(p)
                        flag = 1
                    L.pop(-1)
                    turn = 1
                else :
                    q = L[0]
                    if flag != 0 :
                        ans += abs(p-q)
                    else :
                        B.append(q)
                        flag = 1
                    L.pop(0)
                    turn = 0

        ans += abs(r-B[0])
        ANS.append(ans)
        
    else :
        while len(L2) != 0 :
            if len(L2) == 1 :
                r = L2[0]
                L2.pop(0)
            else :
                if turn == 0 :
                    p = L2[-1]
                    if flag != 0 :
                        ans += abs(p-q)
                    else :
                        B.append(p)
                        flag = 1
                    L2.pop(-1)
                    turn = 1
                else :
                    q = L2[0]
                    if flag != 0 :
                        ans += abs(p-q)
                    else :
                        B.append(q)
                        flag = 1
                    L2.pop(0)
                    turn = 0

        ans += abs(r-B[0])
        ANS.append(ans)
        
        
print(max(ANS))


Measured memory_bytes: 9172
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    let mut ans = 0;

    for i in 0..s.len() {
        if s[i] != t[i] {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 3900
N = gets.chomp.to_i
AS = gets.chomp.split.map(&:to_i)

box = [0] * (N + 1)
N.downto(1) do |i|
  sum = 0
  (2 * i).step(N, i) do |j|
    sum += box[j]
  end
  box[i] = 1 if (sum % 2) != AS[i - 1]
end

puts box.inject(0, &:+)
puts box.each_index.select { |i| box[i] == 1}.join(" ")


Measured memory_bytes: 22532
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 2e5 + 15;
const ll INF = (ll) 1e18;
ll arr[MAX];
ll cnt[MAX];
ll memo[MAX][5];
bool visited[MAX][5];
int n;
int max_jumps;

ll roll(int idx, int jumped) {
    if ((n & 1) && idx == n && jumped == 0) {
        return 0;
    }
    if (idx > n) {
        return 0;
    }
    ll &ans = memo[idx][jumped];
    if (visited[idx][jumped]) {
        return ans;
    }
    visited[idx][jumped] = true;
    ans = roll(idx + 2, jumped) + arr[idx];
    if (jumped < max_jumps) {
        ans = max(ans, roll(idx + 1, jumped + 1));
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    fori (i, 1, n + 1) cin >> arr[i];
    arr[n + 1] = -INF;
    ford (i, n, 1) {
        cnt[i] = max(arr[i] + cnt[i + 2], arr[i + 1] + cnt[i + 3]);
    }
    memset(memo, -1, sizeof memo);
    if (n % 2 == 0) {
        max_jumps = 1;
        cout << roll(1, 0) << endl;
    }
    else {
        max_jumps = 2;
        cout << roll(1, 0) << endl;
    }
    return 0;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int X;
  cin>>X;
  vector<bool>b(1000000,true);
  b[0]=false;
  b[1]=false;
  for(int i=2;i*i<1000000;i++){
    if(b[i]){
      for(int j=i+i;j<1000000;j+=i)b[j]=false;
    }
  }
  for(int i=X;i<1000000;i++){
    if(b[i]){
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 384
s = input()
n=int(s[0])
s = input().split()
d={}
dc={}
summ=0
for i in s:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
for i in d:
    n = d[i]
    if n>1:
        e=n*(n-1)/2
        summ+=e
        dc[i]=e
    else:
        dc[i]=0
for i in s:
    n = d[i]-1
    e = n*(n-1)/2
    print(int(summ-dc[i]+e))


Measured memory_bytes: 36768
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int c = scan.nextInt();
		int r = scan.nextInt();
		int[] s = new int[r + 1];
		for(int i = 0; i < c; i++){
			int sum = 0;
			int a = scan.nextInt();
			System.out.print(a);
			sum += a;
			s[0] += a;
			for(int j = 1; j < r; j++){
				a = scan.nextInt();
				System.out.print(" " + a);
				sum += a;
				s[j] += a;
			}System.out.println(" " + sum);
			s[r] += sum;
		}
		System.out.print(s[0]);
		for(int i = 1; i < r + 1; i++){
			System.out.print(" " + s[i]);
		}System.out.println();

	}

}

Measured memory_bytes: 32192
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

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

	          ll A,B,C;
	          cin >> A >> B >> C;
	          cout << min(A+B+1LL,C)+B << endl;

	          return 0;
}


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

using namespace std;

typedef long long lli;

const lli N = 100;
const lli M = 100000;
const lli INF = 1 << 28;

typedef pair<lli, lli> P;

lli n, m, hp[N], sm[M+1], am[M+1];
vector<P> s, a;

int main(){
	while(cin >> n && n){
		s.clear();
		a.clear();
		for(lli i=0;i<n;i++) cin >> hp[i];
		cin >> m;
		for(lli i=0;i<m;i++){
			string ran;
			lli mp, da;
			cin >> ran >> mp >> ran >> da;
			if(ran == "All") a.push_back(P(da, mp));
			else s.push_back(P(da, mp));
		}
		sort(s.begin(), s.end());
		sort(a.begin(), a.end());
		fill(sm, sm+M+1, INF);
		fill(am, am+M+1, INF);
		sm[0] = am[0] = 0;
		for(lli i=0;i<M;i++){
			for(lli j=0;j<(lli)s.size();j++){
				lli nx = min(M, i + s[j].first);
				sm[nx] = min(sm[nx], sm[i] + s[j].second);
			}
			for(lli j=0;j<(lli)a.size();j++){
				lli nx = min(M, i + a[j].first);
				am[nx] = min(am[nx], am[i] + a[j].second);
			}
		}
		lli valm[2] = {sm[M], am[M]};
		for(lli i=M;i>=0;i--){
			valm[0] = min(valm[0], sm[i]);
			valm[1] = min(valm[1], am[i]);
			sm[i] = valm[0];
			am[i] = valm[1];
		}
		lli ans = INF;
		for(lli i=0;i<=M;i++){
			lli tmp = am[i];
			for(lli j=0;j<n;j++) tmp += sm[max(0LL, hp[j] - i)];
			ans = min(ans, tmp);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2784
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, k;
    cin >> n >> k;
    n = (n + 1) / 2;
    if (n >= k)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

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

int main()
{
  string str;
  int a, b, c, d;
  a = 1;
  b = 0;
  c = 0;
  while (cin >> str){
    if ((str[0] == 'A' && str[2] == 'B') || (str[0] == 'B' && str[2] == 'A')){
      d = a;
      a = b;
      b = d;
    }
    else if ((str[0] == 'B' && str[2] == 'C') || (str[0] == 'C' && str[2] == 'B')){
      d = b;
      b = c;
      c = d;
    }
    else {
      d = a;
      a = c;
      c = d;
    }
  }
  if (a == 1){
    cout << "A";
  }
  else if (b == 1){
    cout << "B";
  }
  else {
    cout << "C";
  }
  cout << endl;

  return 0;
}
    

Measured memory_bytes: 1176
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}

int digit(int n){
    int sum = 0;
    while(n != 0){
        sum += n % 10;
         n = n / 10;
    }
    return sum;
}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    int a, b;
    cin >> a >> b;
    cin >> s;
    for(int i = 0; i < a; ++i){
        if(!(s[i] >= '0' && s[i] <= '9')){
            cout << "No";
            exit(0);
        }    
    }
    if(s[a] != '-'){
        cout << "No";
        exit(0);
    }
    for(int i = a + 1; i <= a + b; ++i){
        if(!(s[i] >= '0' && s[i] <= '9')) {
            cout << "No";
            exit(0);
        }  
    }
    cout << "Yes";
}

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

using namespace std ;

int main()
{
    string a , b , t ;
    cin >> a >> b ;
    int x , y ;
    cin >> x >> y ;
    cin >> t ;
    if(t == a)x-- ;
    else y-- ;
    cout << x << ' ' << y ;
    return 0 ;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>
#include<atcoder/segtree>
#include <atcoder/lazysegtree>
#include <atcoder/modint>



using namespace std;
using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 998244353;

using mint = modint998244353;

struct S {
    mint a;
    int sz;
};

struct F {
    mint a;
};

vector<mint> pw, sm;

S op(S l, S r) {
    return S{l.a * pw[r.sz] + r.a, r.sz + l.sz}; 
}

S e() { return S{0, 0}; }

S mapping(F l, S r) { 
    if (l.a == 0)
        return r;
    return S{l.a * sm[r.sz - 1], r.sz}; 
}

F composition(F l, F r) { 
    if (l.a == 0)
        return r;
    return l; }

F id() { return F{0}; }



void solve() {
    int n, q;
    cin >> n >> q;
    pw.resize(n + 5);
    pw[0] = 1;
    for (int i = 1; i < pw.size(); ++i)
        pw[i] = pw[i - 1] * 10;
    sm.resize(pw.size());
    sm[0] = pw[0];
    for (int i = 1; i < sm.size(); ++i)
        sm[i] = sm[i - 1] + pw[i];

    lazy_segtree<S, op, e, F, mapping, composition, id> seg
    (vector<S>(n, S{1, 1}));
    for (int i = 0; i < q; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        //cout << seg.all_prod().a.val() << "\n";
        seg.apply(a - 1, b, F{c});
        cout << seg.all_prod().a.val() << "\n";
    }

    
}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1){
        c-=b;
        if (c<=0){
            cout << "Yes" << endl;
            return 0;
        }
        a-=d;
        if (a<=0){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
import collections

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

k=int(input())
cnt=collections.defaultdict(int)
for i in range(1,k+1):
  for j in range(1,k+1):
    cnt[gcd(i,j)]+=1
ans=0
for i in range(1,k+1):
  for key in cnt.keys():
    ans+=gcd(i,key)*cnt[key]
print(ans)

Measured memory_bytes: 9384
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = sorted([[a[i][0] + a[i][1], a[i][0]] for i in range(n)])
taka = 0
aoki = 0

for i in range(n):
  if i % 2 == 0:
    taka += b[n - i - 1][1]
  else:
    aoki += b[n - i - 1][0] - b[n - i - 1][1]

print(taka - aoki)

Measured memory_bytes: 38936
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    cd = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    for i, a in enumerate(ab):
        a, b = a
        no = 0
        mt = 10 ** 10
        for j, c in enumerate(cd):
            c, d = c
            tt = abs(a - c) + abs(b - d)
            if tt < mt:
                mt = tt
                no = j + 1
        print(no)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39280
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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 || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/
int main(){
    int N,K; cin >> N >> K;
    int ans = 0;
    for (int i = 0; i < N; i++){
        int h; cin >> h;
        if (h >= K) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int main() {
 bool f = true;
     int N; cin >> N;
     string S; cin >> S;
     if(N%2!=0) {f=false;}
     else {
     for(int i=0; i<=(N-1)/2; i++) {
       if(S[i]==S[i+1+(N-1)/2])  continue;
       else {f=false; break;}
       }
     } 
     
if(f) cout << "Yes" << endl;
else cout << "No" << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| min!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| max!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn is_imbalance(s: &str) -> bool {
    let c = s.chars().nth(0).unwrap();
    2 * s.chars().filter(|&d| c == d).count() > s.len()
}

fn main() {
    let mut sc = Scanner::new();
    let s: String = sc.cin();
    for i in 0..s.len() {
        for j in i+2..i+4 {
            if j > s.len() { continue }
            if is_imbalance(&s[i..j]) {
                // trace!(&s[i..j]);
                put!(i + 1, j);
                return;
            }
        }
    }
    put!(-1, -1);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


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

#define mem(f, v) memset(f,v,sizeof(f))
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);

typedef long long ll;
const int maxn = 100010;
const int inf = ~(1u << 31u);
const ll linf = ~(1llu << 63u);

using namespace std;

ll d[maxn];

struct node{
    ll n, m;
    node(ll n, ll m) : n(n), m(m) {}
    bool operator < (const node & t) const{
        if(n < t.n && m < t.m) return true;
        if(n == t.n) return m < t.m;
        if(m == t.m) return n < t.n;
        return false;
    }
};

ll get(ll n, ll x, ll y){
    if(x > n - x) x = n - x;
    if(y > n - y) x = n - y;
    return x > y ? x : y;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> d[i];
    }

    sort(d+1, d+1+n);
    n = unique(d+1, d+1+n) - (d+1);

    vector <node> dd;

    for(int i = n; i >= 1; i --){
        int x = lower_bound(d+1, d+1+n, d[i] / 2) - d;
        x = get(d[i], d[x], d[x-1]);
        dd.emplace_back(d[i], x);
    }

    sort(dd.begin(), dd.end());
    auto res = *dd.rbegin();
    if(res.m != d[lower_bound(d+1, d+1+n, res.m) - d]){
        res.m = res.n - res.m;
    }
    cout << res.n << " " << res.m << endl;

    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

int main() {
    int totaltime=10; // MON-FRI*AM/PM
    int n; cin>>n;
    
    int timetable[n][totaltime];
    for (int i=0; i<n; i++) for (int j=0; j<totaltime; j++) cin>>timetable[i][j];

    int profit[n][totaltime+1];
    for (int i=0; i<n; i++) for (int j=0; j<(totaltime+1); j++) cin>>profit[i][j];

    int ans;
    for (int p=1; p<pow(2, totaltime); p++) {
        int max_profit=0;

        for (int i=0; i<n; i++) {
            int match_count=0;

            for (int j=0; j<totaltime; j++) {
                if ((p>>j&1)==1 && timetable[i][j]==1) match_count++;
            }
            max_profit += profit[i][match_count];
        }

        if (p==1) {
            ans=max_profit;
        } else if (ans < max_profit) {
            ans=max_profit;
        }
    }

    cout<<ans<<endl;
}



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

long long cnt;
int A[1000000];
int n;
vector<int> G;

// 間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g) {
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
  A[j + g] = v;
  }
}

void shellSort(int A[], int n) {
  // 数列Gを生成
  for (int h = 1; ;) {
    if (h > n) break;
    G.push_back(h);
    h = h * 3 + 1;
  }
  for (int i = G.size() - 1; i >= 0; i--) {
    insertionSort(A, n, G[i]);
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  cnt = 0;

  shellSort(A, n);

  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i--) {
    cout << G[i];
    if (i) cout << " ";
  }
  cout << endl;
  cout << cnt << endl;
  for (int i = 0; i < n; i++) {
    cout << A[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 7048
#include "bits/stdc++.h"

#define INF 200000000
#define FER 0.0000000001

using namespace std;

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

int dp[100001];

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

	fill(dp, dp + 100001, INT_MAX);
	
	int n;

	cin >> n;

	int a;
	int length = 1;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (dp[length - 1] < a)
		{
			dp[length++] = a;
		}
		else
		{
			(*lower_bound(dp, dp + length, a)) = a;
		}
	}

	cout << length << endl;
	
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;




int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll n, a, b;
    cin >> n >> a >> b;
    ll d = b - a;


    ll ans = min(a + (b - a - 1) / 2, n - b + 1 + (b - a - 1) / 2);

    if (d % 2) {
        cout << ans;
    }

    else {
        cout << min(ans, d / 2);
    }


}

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

int main(){
  string S;
  cin >> S;
  if(S=="Sunny"){
    cout << "Cloudy" << endl;
    return 0;
  }
  if(S=="Cloudy"){
    cout << "Rainy" << endl;
    return 0;
  }
  cout << "Sunny" << endl;
  return 0;
}

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define REP(i, n) for(int64_t i=0;i<n;i++)
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal>palvec;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;


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

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    REP(i, n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}

void COMinit(int m, lvec &fac, lvec &finv){
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; 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 pow_mod(ll a, ll n){
  ll x = 1;
  while(n > 0){
    if(n&1){
      x = x*a % MOD;
    }
    a = a*a %MOD;
    n >>= 1;
  }
  return x;
}
ll COM(int n, int k, const lvec& fac, const lvec &finv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll 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 P(ll n, ll m){
    ll s = 1;
    ll cnt=n;
    REP(i, n-m){
        s*=cnt % MOD;
        s%=MOD;
        --cnt;
    }
    return s;
    
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    int m = 2*1e5+1;
    lvec fac(m), finv(m);
    COMinit(m, fac, finv);
    ll coma = P(n, n-a) * (finv[a]%MOD) % MOD, comb = P(n, n-b) * (finv[b] % MOD) % MOD;
    ll tot = pow_mod(2, n)-1;    
    ll ans = (tot + (MOD-coma)  + (MOD-comb))%MOD;
    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    ll ans = 1,mod = 1e9+7;
    
    vector<int> v(1001,0);
    vector<vector<int>> num(1001);
    vector<bool> seen(1001,true);
    vector<bool> isprime(1001,false);
    
    for(int i = 2;i <= n;i++){
        int N = i;
        for (int a = 2; a * a <= N; ++a){
            if (N % a != 0) continue;
            int ex = 0;
            
            while (N % a == 0) {
                ++ex;
                N /= a;
            }
            v[a] += ex;
        }
        
        if(N == i){
            v[i]++;
            isprime[i] = true;
        } else v[N]++;
    }
    
    for(int i = 2;i <= n;i++){
        if(!isprime[i])continue;
        ans *= (v[i] + 1);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cmath>

constexpr int MAX=200;

int d,n;

int t[MAX];
int a[MAX],b[MAX],c[MAX];

int dp[MAX/*テヲツ猟・テ」ツ?ォテ」ツ?。*/][MAX/*テ、ツサツ甘ヲツ猟・*/];

int main() {
	std::cin>>d>>n;
	for(int i=0;i<d;++i)
		std::cin>>t[i];
	for(int i=0;i<n;++i)
		std::cin>>a[i]>>b[i]>>c[i];

	for(int i=1;i<d;++i){
		for(int j=0;j<n;++j){
			if(a[j]<=t[i]&&t[i]<=b[j]){
				for(int k=0;k<n;++k){
					if(a[k]<=t[i-1]&&t[i-1]<=b[k])
						dp[i][j]=std::max(dp[i][j],dp[i-1][k]+std::abs(c[j]-c[k]));
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<n;++i)
		ans=std::max(ans,dp[d-1][i]);
	std::cout<<ans<<std::endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(20) << x << endl
const int MOD = 1e9 + 7;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 1e-8;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

template <int mod = 1000000007>
struct Combination {
  std::vector<long long> fac, finv, inv;
  Combination(const long long n) : fac(n + 1, 0), finv(n + 1, 0), inv(n + 1, 0) {
    for (long long i = 0; i < n + 1; ++i) {
      bool one_or_zero = i == 0 || i == 1;
      fac[i] = one_or_zero ? 1 : fac[i - 1] * i % mod;
      inv[i] = one_or_zero ? 1 : mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = one_or_zero ? 1 : finv[i - 1] * inv[i] % mod;
    }
    inv[0] = 0;
  }
  long long operator()(const long long n, const long long r) {
    if (n < r || n < 0 || r < 0)
      return 0;
    else if (n == r || r == 0)
      return 1;
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
  }
};


signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;
  Combination<MOD> comb(n * m);
  ll ans = 0;
  rep(i, n) rep(j, m) {
    ll tmp = ((n - i) * (m - j) % MOD) * (i + j) % MOD;
    tmp %= MOD;
    if(i != 0 && j != 0) tmp *= 2;
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }

  ans *= comb(n * m - 2, k - 2);
  out(ans % MOD);


  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
main(){
 long long n,t[1000]={},a[1000]={},j;
 cin>>n>>t[0]>>a[0];
 for(int i=1;i<n;i++){
  cin>>t[i]>>a[i];
   j=max((a[i-1]-1)/a[i],(t[i-1]-1)/t[i])+1;
   a[i]*=j;t[i]*=j;
 }
 cout<<a[n-1]+t[n-1]<<endl;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int r, D;
  cin >> r >> D;
  vector<int> x(11);
  cin >> x[0];
  REP1(i, 10) {
    x[i] = r * x[i - 1] - D;
    cout << x[i] << endl;
  }
  return 0;
}

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

using namespace std;

long long int pow3(long long int a){
	return a * a * a;
}

int main(){
	
	long long int n;
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		long long int min;
		min = pow3(n);
		for(long long int i = 1; i < n; i++){
			for(long long int j = 1; j < n; j++){
				if(pow3(i) + pow3(j) > pow3(n)){
					continue;
				}else if(min > pow3(n) - pow3(i) - pow3(j)){
					min = pow3(n) - pow3(i) - pow3(j);
				}
			}
		}
		printf("%d\n", min);
	}
	
	return 0;
}

Measured memory_bytes: 1144
#!usr/bin/env python3
n = int(input())
p = [int(input()) for i in range(n)]
f = [0]*(n+1)
m = [n-1]*(n+1)
for i in p:
    if f[i-1]:
        m[i] = m[i-1]-1
    f[i] = 1
print(min(m))


Measured memory_bytes: 62424
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll n,k,b;
vec A;
ll ok=-1e18,ng=1e18+1;
int solve(ll x){
    ll ans=0;
    rep(i,n){
        if(A[i]<0){
            ll a;
            if(x>0) a=(x-1)/A[i];
            else a=(x+A[i])/A[i];
            ans+=A.end()-lower_bound(all(A),a);
        }
        else if(A[i]==0){
            if(x>0) ans+=n;
        }
        else{
            ll a;
            if(x>0) a=(x-1)/A[i];
            else a=(x-A[i])/A[i];
            ans+=upper_bound(all(A),a)-A.begin();
        }
        if(A[i]*A[i]<x) ans--;
    }
    ans=ans/2;
    //cout<<x<<" "<<ans<<endl;
    if(ans<k) return 1;
    return 0;
}
int search(){
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        if(solve(mid)) ok=mid;
        else ng=mid;
    }
}
int main(){
    cin>>n>>k;
    rep(i,n) cin>>b,A.push_back(b);
    sort(all(A));
    search();
    cout<<ok<<"\n";
}

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

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

int main(){
    int n, x;
    cin >> n >> x;
    vector<ll> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
        v[i] = abs(v[i] - x);
    }

    ll d = 0;
    for(int y:v) d = gcd(d, y);
    cout << d << endl;
    return 0;
}

Measured memory_bytes: 1024
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;cin>>s;
	ll n=s.size(),i,j;
	ll dp[2019]={};
	dp[0]=1;
	ll prev=0,sum=0;
	for(i=0;i<n;i++){
		ll p=(prev*10+(s[i]-'0'))%2019;
		sum+=dp[p];
		dp[p]++;
		ll dp1[2019]={};
		//dp1[0]=1;
		for(j=0;j<2019;j++){
			dp1[(j*10)%2019]+=dp[j];
		}
		for(j=0;j<2019;j++)
			dp[j]=dp1[j];
		prev=p;
		//dp[prev]++;
	}
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 3760
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

/**
 * Created by Seiya on 2016/10/16.
 */
public class Main {

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

        int a, b, c;
        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();



        if(a + b == c || a + c == b || b + c == a){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }


}


Measured memory_bytes: 10324
#include <bits/stdc++.h>
#include <algorithm>
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;}

const int INF = 100000; 

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

    vector<int> a(26, 0);
    for(int i = 0; i < s.size(); i++){
        a[s[i] - 'a']++;
    }

    for(int i = 0; i < 26; i++){
        if(a[i] > 1){
            cout << "no" << endl;
            return 0;
        }
    }

    cout << "yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;

#define M 100010

int ex(int a,int b){int ans=1;while(b){if(b&1)ans=(ans*a)%md;a=(a*a)%md,b/=2;}return ans;}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	
   	int n;cin>>n;
   	int ans=ex(10,n)-2*ex(9,n);
   	(ans+=2*md)%=md;
   	ans+=ex(8,n);
   	ans=(ans+md)%md;
   	cout<<ans;
   	
    return 0;
}

Measured memory_bytes: 3648
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let f: Vec<Vec<usize>> = (0..n).map(|_| util::gets()).collect();
    let p: Vec<Vec<i64>> = (0..n).map(|_| util::gets()).collect();

    let f_digit: Vec<usize> = f.iter()
        .map(|v| {
            let mut d = 0;
            for (i, &b) in v.iter().enumerate() {
                if b == 1 {
                    d |= 1 << i;
                }
            }
            d
        })
        .collect();

    let mut ans = i64::min_value();
    for t in 1..1 << 10 {
        let mut profit = 0i64;

        for i in 0..n {
            let c = (t & f_digit[i]).count_ones();
            profit += p[i][c as usize];
        }
        ans = max(ans, profit);
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<queue>
using namespace std;

typedef pair<int, int> pi;
pair <int, int>p;
pair <int, int> po;
int n, m,c;
char ma[1001][1001];
int ix, iy,x,y;
int te[1001][1001];
int xw[4] = { 1, 0, -1, 0 };
int yw[4] = { 0, 1, 0, -1 };
char name[10] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
int nat = 0;
int na;
int op = 10000;
int main()
{	queue<pi> q;
	cin >> n >> m >> na;
	for (int i = 0; i < n; i++){
		for (int i2 = 0; i2 < m; i2++){
			cin >> ma[i][i2];
			te[i][i2] = op;
			if (ma[i][i2] == 'S'){
				p.first = i;
				p.second = i2;
			}
		}
	}
	
	int count;

	count = 0;
	q.push(p);
	
	te[p.first][p.second] = 0;
	while (!q.empty()){
		p = q.front();
		po = p;
		q.pop();
		
		for (int i = 0; i < 4; i++){
			x = p.first + xw[i];
			y = p.second + yw[i];
			if (0<=x && x<n&&0<=y && y<m&&ma[x][y] != 'X'&&te[x][y] == op){

				if (ma[x][y] == name[nat]){
					po.first = x;
					po.second = y;
					while (!q.empty()){ q.pop(); }
					q.push(po);
					po = p;
					count += te[p.first][p.second] + 1;
					nat++; 
					if (nat == na){ cout << count << endl; return 0; }
					//memset(te, op, sizeof(te));
					for (int i2 = 0; i2 <= n; i2++){
						for (int i3 = 0; i3 <= m; i3++){
							te[i2][i3] = op;
						}
					}
					te[x][y] = 0;
					break;
				}

				else{
					po.first = x;
					po.second = y;
					q.push(po);
					po = p;
					te[x][y] = te[p.first][p.second] + 1;
				}
			}
		}
	}
}

Measured memory_bytes: 6104
#include<stdio.h>

int solve(int,int);

int n,A[50];

int main(){
  int i,m,q;

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m)) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int i,int m){
  int res;
  
  if(m==0) return 1;
  if(i>=n) return 0;
  
  res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
  }



Measured memory_bytes: 2048
/**
 *    author:  FromDihPout
 *    created: 2020-06-26
**/

#include <bits/stdc++.h>
using namespace std;


int digits(int n) {
    int cnt = 0;
    while (n > 0) {
        cnt++;
        n /= 10;
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long n;
    cin >> n;
    
    for (int i = floor(sqrt(n)); i >= 1; i--) {
        if (n % i == 0) {
            cout << digits(n / i) << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
///PROBLEM CODE - SEGDIR (CodeChef)
///SOLUTION FOR 3rd problem of ICPC Online round 2k19!!

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define pb push_back


///Input/Output macros!
#define gi(x) scanf("%d", &x)
#define gi2(x, y) scanf("%d%d", &x, &y)
#define gi3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define gill(x) scanf("%lld", &x)
#define gill2(x, y) scanf("%lld%lld", &x, &y)
#define gill3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define pi(x) printf("%d\n", x)
#define pill(x) printf("%lld\n", x)


///Basic Debugging macros!
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(ll __i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(ll __i__=0;__i__<r;__i__++){for(ll __j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}

using namespace std;

///Power of 2 till 2^31!
ll pow2[32] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648};

///Power function!
ll power(ll x,ll y)
{
        ll res = 1;
        while(y>0){
            if(y&1)
                res *= x;
            y>>=1;
            x*=x;
        }
        return res;
}

///Basic Sieve of Eratosthenes!
void Sieve(ll n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool isPerfectSquare(ll x){ ll s = sqrt(x); return (s*s == x);}

bool isFibonacci(int n){return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4);}

bool isPrime(int n){if (n <= 1)return false;if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0)return false;
    return true;
}

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;


const int MOD = 1000000007;
const long double PI = 4*atan((long double)1);
const ll INF = 1e18;

int main()
{
    int n;
    cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        a.push_back(val);
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            //if(i==j)continue;
            sum+=(a[i]*a[j]);
        }
    }
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
long long n, m, cnt[100001], sc=0, pen=0;
bool ac[100001];

int main(){
	memset(ac,0,sizeof ac);
	memset(cnt,0,sizeof cnt);
	cin >> n >> m;
	for (int i=0;i<m;i++){
		long long p;
		string s;
		cin >> p >> s;
		if (ac[p]) continue;
		if (s=="WA") cnt[p]++;
		else if (s=="AC"){
			ac[p]=1;
			sc++;
			pen+=cnt[p];
		}
	}
	cout << sc << " " << pen << "\n";
}

Measured memory_bytes: 1152
n,a=int(input()),list(map(int,input().split()))
c,m=0,abs(a[0])
for i in range(n):
  if a[i]<0:c+=1
  m=min(abs(a[i]),m)
ans=0
for i in range(n):ans+=abs(a[i])
if not(m==0 or c%2==0):ans-=m*2
print(ans)

Measured memory_bytes: 14332