akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <functional>


using namespace std;

#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<vi> vii;


const int INF = 100000000;
const double EPS = 1e-10;
int mod=1000000007;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int h, w, n;
vector<string> s;

bool outOfRange(int y, int x){
	if(x < 0 || x >= w || y < 0 || y >= h) return true;
	return false;	
}

int calc(int y, int x, int c, int num){
	//cout<<y<<x<<" "<<c<<" "<<num<<endl;
	if(num == n) return c;
	queue<pair<int, pii> > q;
	vector<vi> v(h, vi(w, -1));
	v[y][x] = 0;
	pair<int, pii> p(c, mp(y, x));
	q.push(p);
	while(!q.empty()){
		//cout<<"  "<<q.size()<<endl;
		p = q.front(); q.pop();
		int tx = p.se.se, ty = p.se.fi, tc = p.fi;
		for(int i = 0; i < 4; i++){
			int nx = tx + dx[i], ny = ty + dy[i];
			if(outOfRange(ny, nx) || s[ny][nx] == 'X' || v[ny][nx] != -1) continue;
			//cout<<ny<<" "<<nx<<endl;
			if(s[ny][nx] == '1' + num){
				//q = queue<pair<int, pii> >;
				//cout<<"AAA"<<endl;
				return calc(ny, nx, tc + 1, num + 1);
			}
			//cout<<" "<<nx<<" "<<ny<<endl;
			v[ny][nx] = tc + 1;
			q.push(mp(tc + 1, mp(ny, nx)));
		}
	}
	return -1;
}

int main(){
	cin>>h>>w>>n;
	//cout<<h<<" "<<w<<" "<<n<<endl;
	s = vector<string>(h);
	rep(i, h) cin>>s[i];
	//rep(i, h) cout<<s[i]<<endl;
	//cout<<s[2][2]<<endl;
	int sx, sy;
	rep(i, h) rep(j, w){
		if(s[i][j] == 'S'){
			sy = i; sx = j;
		}
	}
	//cout<<sy<<" "<<sx<<endl;
	cout<<calc(sy, sx, 0, 0)<<endl;
}

Measured memory_bytes: 37700
x,y,z,k = map(int,input().split())
xlist = list(map(int,input().split()))
ylist = list(map(int,input().split()))
zlist = list(map(int,input().split()))
xlist.sort(reverse=True)
ylist.sort(reverse=True)
zlist.sort(reverse=True)
xlist[k:] = []
ylist[k:] = []
zlist[k:] = []
ans = []
for i in xlist:
     for j in ylist:
          ans.append(i+j)
ans.sort(reverse=True)
ans[k:]=[]
Ans = []
for i in ans:
     for j in zlist:
          Ans.append(i+j)
Ans.sort(reverse=True)
Ans[k:]=[]
for i in Ans:
     print(i)

Measured memory_bytes: 183024
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    n, a, b = map(int, rl().split())
    c = n // (a + b)
    d = n % (a + b)
    ans = c * a
    if a > d:
        ans += d
    else:
        ans += a
    print(ans)


if __name__ == '__main__':
    solve()


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


#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define fr(i,a,b) for(int i = a ; i < b ; ++i)
#define backfr(i,a,b) for(int i = a ; i > b ;--i)
#define all(v) v.begin() , v.end()
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define show(x) cout << #x <<" = " << x << endl
#define fastio ios_base::sync_with_stdio(0)

typedef long long ll;
typedef vector < int > vi;
typedef vector < vector <int > > vvi;
typedef pair <int , int > ii;

typedef vector < pair <int , int> > vii;
int main()
{
	fastio;cin.tie(0);cout.tie(0);
	long long int h,ans=0,c=0,n;
	cin>>h;
	while(h>=1)
	{
		h = h/2;
		n=pow(2,c);
		ans+=n;
		++c;
	}
	cout<<ans;
	return 0;
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  string s; cin >> s;
  int ans = 0, cnt=0;
  for (int i = 0; i < 3; ++i){
    if(s[i]=='R') cnt++, ans = max(ans, cnt);
    else  cnt = 0;
  }
  ans = max(ans, cnt);
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);

int main() {
  int n,a[3100];
  cin >> n;
  int sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cout << sum - n << endl; 
}

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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=1e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int a;

int main()
{
    read(a);
    printf("%d\n",a+a*a+a*a*a);
    return 0;
}

Measured memory_bytes: 3760
n = $<.gets.to_i
@kuras = $<.readlines.map {|i| i.split.map(&:to_i)}
@kuras.each {|k| k[2] *= 20}

@edges = Array.new(n) {[nil] * n}
n.times do |i|
  (i + 1...n).each {|j| @edges[i][j] = @edges[j][i] = (@kuras[i][1] - @kuras[j][1]).abs}
end

all = (1 << n) - 1
@memo = Array.new(n) {[]}
n.times {|i| @memo[i][all ^ (1 << i)] = [0, [@kuras[i][0]]]}

def try(start, reached = 0, w = 0)
  return @memo[start][reached] if @memo[start][reached]
  n = @kuras.size
  now = @kuras[start]
  min_time = Float::INFINITY
  min_order = nil
  nr = reached | (1 << start)
  w0 = w + now[2]
  n.times do |nxt|
    next if (nr & (1 << nxt)).nonzero?
    time, order = try(nxt, nr, w0)
    time += @edges[start][nxt] * (70 + w0).to_r / 2000
    if time < min_time
      min_time = time
      min_order = [now[0]] + order
    end
  end
  @memo[start][reached] = [min_time, min_order]
end

puts (0...n).map {|i| try(i)}.sort_by(&:first).first.last.join(" ")



Measured memory_bytes: 65360
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int X) {
  return X * X;
}
int main() {
  int N;
  long long int D;
  cin >> N >> D;
  int count = 0;
  for(int i = 0; i < N; i++) {
    long long int X, Y;
    cin >> X >> Y;
    if(power(X) + power(Y) <= power(D)) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3628
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define PI          3.14159265358979323846
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ld          long double
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
void tc(){
    ll a, b, x;
    cin >> a >> b >> x;
    if(a == 0){
        cout << b / x + 1;
    }else{
        cout << b / x - (a - 1) / x;
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) tc();
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    left = a + b;
    right = c + d;

    string answer = "";
    
    if (left > right){
        answer = "Left";
    } else if (left < right) {
        answer = "Right";
    } else {
        answer = "Balanced";
    }

    cout << answer;
}

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


a, b, m = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

candidate = [min(A)+min(B)]

for _ in range(m):
    x, y, c = map(int, input().split())
    cost = A[x-1] + B[y-1] - c
    candidate.append(cost)

print(min(candidate))



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

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = Array.ConvertAll(line, int.Parse);
            var k = (n+2) /2;
            var d = new Dictionary<int, int>();
            for (int i = 0; i < n; i++)
                if (d.ContainsKey(a[i])) d[a[i]]++;
                else d[a[i]] = 1;
            var dm = d.Values.Max();
            var ans = d.First(x => x.Value == dm).Key;
            if (dm >= k) Console.WriteLine(ans);
            else Console.WriteLine("NO COLOR");
        }
    }
}

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

int solve(int n, int k, int s) {
    function<int(int, int, int)> dfs = [&](int i, int p, int t) {
        if (i == k) return int(t == 0);
        int cnt = 0;
        for (int e = p + 1, u = min(n, t); e <= u; ++e) cnt += dfs(i + 1, e, t - e);
        return cnt;
    };
    return dfs(0, 0, s);
}

int main() {
    for (int n, k, s; cin >> n >> k >> s, n | k | s;) cout << solve(n, k, s) << endl;
}

Measured memory_bytes: 3000
def main():
    n,k = map(int,input().split())
    h = list(map(int,input().split()))

    inf = 10**18
    # min -> inf, max -> 0
    dp = [inf]*n

    # shoki joken
    dp[0] = 0
    for i in range(1,n):
        for j in range(1,min(i,k)+1):
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
    print(dp[-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 52448
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

int main() {
	int cnt = 0, n, d, x;
	cin >> n;

	vector<int>a(n + 1);
	vector<bool>isR(n + 1);
	rep(i, n)
		cin >> a[i + 1];
	a[0] = 0; a.push_back(0);

	rep(i, n + 1) {
		cnt += abs(a[i] - a[i + 1]);

		isR[i] = a[i] < a[i + 1];
	}
	rep(i, n) {
		int ans;
		ans = cnt;
		if (a[i] <a[i + 1] && a[i + 1]<a[i + 2]
			||
			a[i]>a[i + 1] && a[i + 1]>a[i + 2]
			) {
			cout << ans << endl;
		}
		else
			cout << ans - abs(a[i] - a[i + 1]) - abs(a[i + 1] - a[i + 2]) + abs(a[i] - a[i + 2]) << endl;


	}

}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n , d;
    cin >> n >> d;
    d = d * d;
    ll arr[n];
    for(int i = 0 ; i < n ; i++){
        ll x , y;
        cin >> x >> y;
        ll val = x * x + y * y;
        arr[i] = val;
    }
    int ans = 0;
    for(ll i : arr)
        if(i <= d)
            ++ans;
        cout<<ans;
}



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

using namespace std;

const int N = 55;

int n, x, a[N];
long long dp[N][N][N * N];

int main(){
    scanf("%d %d", &n, &x);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k < N * N; k++) {
                if (dp[i][j][k]) {
                    dp[i + 1][j][k] += dp[i][j][k];
                    if (k + a[i + 1] < N * N) dp[i + 1][j + 1][k + a[i + 1]] += dp[i][j][k];
                }
            }
        }
    }

    long long ans = 0;
    for (int i = 1; i <= n; i++) ans += dp[n][i][x * i];
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 71808
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int cur = 0;
    vector<vector<int>> ans(h, vector<int>(w));
    rep(i,h){
        if(i%2 == 0){
            rep(j,w){
                ans[i][j] = cur + 1;
                if(--a[cur] <= 0) cur++;
            }
        }
        else{
            for(int j = w-1; j >= 0; j--){
                ans[i][j] = cur + 1;
                if(--a[cur] <= 0) cur++;
            }
        }
    }
    rep(i,h){
        rep(j,w) cout << ans[i][j] << " ";
        cout << endl;
    }
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N, P;
    string S;
    cin >> N >> P >> S;
    int l = S.size();
    
    int res = 0;
    if(P==2 || P==5) {
        rep(i, l) {
            if(int(S[i]-'0')%P == 0) {
                res += i+1;
            }
        }
    } else {
        reverse(ALL(S));
        vi dp(l+1, 0);
        map<int, int> mp;
        mp[0]++;
        int t = 1;
        rep(i, l) {
            dp[i+1] = (dp[i]+int(S[i]-'0')*t)%P;
            mp[dp[i+1]]++;
            t = (t*10)%P; 
        }

        for(auto &p : mp) {
            res += p.se*(p.se-1)/2;
        }
    }
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2564
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << #x << "=" << (x) << " | "

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    inn(n);
    int a[n][3];
    int dp[n][3];
    rep(i, n) rep(j, 3) {
        inn(x);
        dp[i][j] = a[i][j] = x;
    }


    int ans = std::max(dp[0][0], std::max(dp[0][1], dp[0][2]));
    repr(i, 1, n) {
        dp[i][0] += std::max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] += std::max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] += std::max(dp[i - 1][0], dp[i - 1][1]);
        ans = std::max(dp[i][0], std::max(dp[i][1], dp[i][2]));
    }

    out(ans);
}

int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

    //inn(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


Measured memory_bytes: 2560
//https://atcoder.jp/contests/abc155/tasks/abc155_e
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 (b<a) { a=b; return 1; } return 0;}

//f(3456)=min{f(345)+6,f(346)+4}
ll solve(const string& N) {
    vector<vector<ll>> dp(N.size()+1,vector<ll>(2,0)); //0:そのまま, 1:+1
    dp[0][1]=1;
    FOR(i,0,N.size()){
        ll digit = N.at(i)-'0';
        if (digit==0){
            dp[i+1][0]=dp[i][0];
        }else{
            ll s0 = dp[i][0]+digit;
            ll s1 = dp[i][1]+(10-digit)%10;
            dp[i+1][0]=min(s0,s1);
        }

        ++digit;
        if (digit>=10){
            dp[i+1][1]=dp[i][1];
        }else{//同じ
            ll s0 = dp[i][0]+digit;
            ll s1 = dp[i][1]+(10-digit)%10;
            dp[i+1][1]=min(s0,s1);
        }
    }
    return dp[N.size()][0];
}

ll test(ll t=36){
    auto maisuu = [](ll v){
        ll ret=0;
        while(v>0){
            ret += (v%10);
            v /= 10;
        }
        return ret;
    };

    ll minn = INT32_MAX;
    ll oo,ii;
    FOR(i,t,99999+1){
        auto o = i-t;
        ll tmp = maisuu(i) +maisuu(o); 
        if (chmin(minn, tmp)){
            oo = o;
            ii = i;
        }               
    }
    //dump(t, ii, oo, minn);
    return minn;
}

int main(){
#if 0
    dump(solve("60"));
    FOR(i, 1, 5000){
        auto a=test(i);
        auto b=solve(std::to_string(i));
        if(a!=b) dump(i,a,b);
    }
    return 0;
#endif
#if LOCAL&0
    //std::ifstream in("./test/sample-1.in");
    std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    string N; cin>>N;
    ll ans = solve(N);
    cout<<ans<<endl;
    return 0;
}

int main_() {
    //test(432); return 0;
    // FOR(i, 36, 5000){
    //     test(i);
    // }
    // return 0;
 #if LOCAL&01
     std::ifstream in("./test/sample-2.in");
     //std::ifstream in("./input.txt");
     std::cin.rdbuf(in.rdbuf());
 #else
     cin.tie(0);
     ios::sync_with_stdio(false);
 #endif
    string N; cin>>N;
    ll ans=INT64_MIN;
    vector<ll> sums_d; //反対から累積和
    vector<ll> sums_p; //反対か
    ll sum=0;
    ll sump=0;
    FOR(i,0,N.size()){
        ll digit = N.at(i)-'0';
        sump += digit;
        //sumps_p.push_back(sump);
    }

    for(ll i=N.size()-1;i>=0;--i){
        ll digit = N.at(i)-'0';
        //sump += digit;
        //sums_p.push_back(sump);
        ll v = 10 - digit - 1;
        sum += v;
        sums_d.push_back(sum);
    }
    sums_d.push_back(sum+1);

    //ll ans=INT64_MAX;
    for(ll i=0;i<=sums_p.size();++i){
        ll tmp=sums_p.at(i)+sums_d.at(i+1);
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;

    return 0;
}

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

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        s:Chars,
        t:Chars,
    }
    let ans = s.iter().zip(t.iter()).filter(|&(&c, &d)| c != d).count();
    println!("{}", ans);
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll maxNum = 10e5;

//エラトステネスの篩で素数判定;
// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
};

int main(){
   
    Sieve s = Sieve(maxNum+1);
    
    vector<ll> sumSieve(maxNum+1,0);
    ll sum =0;
    for(int i=1;i<=maxNum;i++){
        if(i%2 ==0){
            continue;
        }
        if(s.isPrime(i) && s.isPrime((i+1)/2)){
            sum ++;
        }
        sumSieve[i]  =sum;
    }

    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        int l,r;
        cin >> l >> r;
        if(l==1){
            cout << sumSieve[r] << endl;
        }else{
            cout << sumSieve[r] -sumSieve[l-2] << endl;
        }
    }


    
    return 0;
}

Measured memory_bytes: 12792
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define ll long long
#define pb push_back
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;

int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll f[2000001];



ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

bool prime[100005];
void seive()
{  memset(prime,true,sizeof(prime));
    for(int i=2;i*i<=100005;i++)
    {
         if(prime[i]==true) {
        for(int j=2*i;j<=(100005);j+=i)
           { prime[j]=false;}
           }

    }
}
bool in(float x1,float y1,float x,float y,float r )
{
    if(abs(x1-x)*abs(x1-x)+abs(y1-y)*abs(y1-y)<=r*r) return true;
    return false;


}


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

	ll T;
   T=1;
   map<int,vector<pair<int,int>> >mp;
	while(T--)
	{
    int n,m;
    cin>>n>>m;
    vector<string>ans(m);
    for(int i=0;i<m;i++)
    {
        
        int a,b;
        cin>>a>>b;
        mp[a].push_back(make_pair(b,i));
        
    }
    
       map<int,vector<pair<int,int>>>::iterator it ;
       for(it=mp.begin();it!=mp.end();it++)
       {
           
           sort(it->second.begin(),it->second.end());
           string u = to_string(it->first);
           if(u.size()<6)
           {
               int l = 6-u.size();
               string b(l,'0');
               u=b+u;
           }
           for(int i = 0 ;i<it->second.size();i++)
           {   string an = to_string(i+1);
                if(an.size()<6)
           {
               int l = 6-an.size();
               string b(l,'0');
               an=b+an;
           }
           an=u+an;
           
               ans[it->second[i].second]=an;
             
           }
       }
       for(int i=0;i<m;i++) cout<<ans[i]<<endl;
}
}


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

#define fi first
#define se second
#define pb push_back

typedef long long LL;
typedef long double LD;

const LL INF = (1LL << 60);

LL s, t;
LL a[200005];

LL effect(LL x) {
  return (x > 0 ? -x * s : -x * t);
}

int main() {

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

  int n, q;
  cin >> n >> q >> s >> t;

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

  for (int i = n; i > 0; i--) {
    a[i] -= a[i-1];
  }

  LL res = 0;
  for (int i = 1; i <= n; i++) {
    res += effect(a[i]);
  }

  while (q--) {
    int l, r; LL h;
    cin >> l >> r >> h;

    res -= effect(a[l]);
    a[l] += h;
    res += effect(a[l]);

    if (r < n) {
      r++;
      res -= effect(a[r]);
      a[r] -= h;
      res += effect(a[r]);
    }

    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 4792
/* ex4_3
    sak_Citrus*/

#include <stdio.h>
#include <stdlib.h>

//関数のプロトタイプ宣言
//1からnumまでの和を計算する関数
int calcHeight(int num);
//解を出す関数
int calcAns(int west, int east);

int main(void)
{
    //標準入力と解
    int west, east,ans;
    scanf("%d %d", &west, &east);
    ans = calcAns(west, east);
    printf("%d\n", ans);
    return 0;
}
int calcAns(int west, int east)
{
    //二つの塔の高さの差の絶対値を取ると、何番目の塔の間にいるか分かる
    int diff = abs(west - east);
    //(元の高さ) - (見えている高さ) = (積雪量)
    int ans = abs(east - calcHeight(diff));
    return ans;
}

int calcHeight(int num)
{
    int ret = 0;
    //1からnまでretにiを足し続ける
    for (int i = 1; i <= num; i++)
    {
        ret += i;
    }
    return ret;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

n, k = map(int, input().split())
ans = 0
for i in range(n + 1):
    if i + 1 < k:
        continue
    diff = (2*n - i) * (i + 1) // 2 - i * (i + 1) // 2 + 1
    ans += diff 
    ans %= MOD
print(ans)

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a / b << " " << a % b << " " << fixed;
	cout.precision(5);
	cout << (double)a / (double)b << endl;

	return 0;
}


Measured memory_bytes: 3292
#include <stdio.h>
#define M 300000
int array[M];

void swap(int *a, int *b){
    int temp = *a;
    *a = *b;
    *b = temp;
}
int check(int N){
    int min = array[0];
    for(int j = 1; j < N; j++){
        if(min > array[j]) return -1;
        min = array[j];
    }
    return 0;
}
int main(void){
    int N, Q, x, y;
    int all = 0;
    scanf("%d", &N);
    for(int i = 0; i < N; i++) scanf("%d", &array[i]);
    for(int i = 0; i < N-1;i++){
        if(array[i] <= array[i+1]) all++;
    }

    scanf("%d", &Q);
    int i;
    for( i = 0; i < Q; i++){
        scanf("%d %d", &x, &y);
        if(x > y) swap(&x,&y);
        if(all == N-1) {
            break;
        }

        //printf("%d\n",all);

        if(x-1 > 0){
            if(array[x-2] <= array[x-1] && array[x-2] > array[y-1] ){
                all--;
            }
            if(array[x-2] > array[x-1] && array[x-2] <= array[y-1]){
                all++;
            }
        }
        if(y < N){
            if(array[y-1] <= array[y] && array[x-1] > array[y]){
                all--;
            }
            if(array[y-1] > array[y] && array[x-1] <= array[y]){
                all++;
            }
        }

        if(y-x > 1){
            if(array[x-1] <= array[x] && array[y-1] > array[x]) all--;
            if(array[x-1] > array[x] && array[y-1] <= array[x]) all++;

            if(array[y-2] <= array[y-1] && array[x-1] < array[y-2]) all--;
            if(array[y-2] > array[y-1] && array[x-1] >= array[y-2]) all++;
        }

        else{
            if(array[x-1] > array[y-1]) all++;
            if(array[x-1] < array[y-1]) all--;
        }

        swap(&array[x-1], &array[y-1]);

    }

    if(all != N-1) printf("-1\n");
    else printf("%d\n",i);
}


Measured memory_bytes: 3892
import java.util.*;
import java.math.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long times = n / (a + b);
    long rest = n % (a + b);
    System.out.println(a * times + Math.min(rest, a));
  }
}

Measured memory_bytes: 22608
/**
 *	author:   fractal
 *	timus:    288481RF
 *	created: 08/15/20 18:13:25
**/

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

#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define szc(x) (int)strlen(x)
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound 
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 1e6 + 2;
const int M = 1e5;
const int mod = 998244353;
const int inf = 2e9 + 3;
const ll INF = 1e16;

/*
	BIN POISK EBANA V ROT
	DP EBANA V ROT
	DO EBANA V ROT
*/

ll x, k, d;

int main() {
	scanf("%lld %lld %lld", &x, &k, &d);
	x = abs(x);
	ll mv = x / d;
	if (mv > k)
		printf("%lld", x - k * d);
	else
		if ((k - mv) % 2 == 0)
			printf("%lld", x - mv * d);
		else
			printf("%lld", abs(x - mv * d - d));
}


Measured memory_bytes: 3860
def gcd(x, y):
    a = x
    b = y
    if(y > x):
        a = y
        b = x
    mod = a % b
    if (mod == 0):
        return b
    else:
        return gcd(b, mod)

def main():
    x, y = map(int, input().split())
    print(gcd(x, y))

main()


Measured memory_bytes: 5600
object Main {

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._

    val N = readLine().toInt
    val s = scala.collection.mutable.Set[Int]()
    (0 until N).foreach { _ =>
      val a = readInt()
      if (s.contains(a))
        s.remove(a)
      else
        s.add(a)
    }
    println(s.size)
  }

}

Measured memory_bytes: 36804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15


int main() {
	int A,B,C,D,E,F;
	cin >> A >> B >> C >> D >> E >> F;
	double max_ratio = -1.0;
	ll water = 0;
	ll sugar = 0;
	for(ll a = 0; true; a++){
		if(100 * A * a > F) break;
		for(ll b = 0; true; b++){
			if(100 * A * a + 100 *B* b > F) break;
			for(ll c = 0; true; c++){
				if(100 * a *A + 100 * B * b + C * c > F) break;
				for(ll d = 0; true; d++){
					if(100 * A * a + 100 * B * b + C * c + D * d > F) break;
					ll weight_water = 100 * A * a + 100 * B *b;
					ll weight_sugar = C * c + D * d;
					ll max_sugar = weight_water / 100 * E;
					if(weight_sugar > max_sugar) break;
					double ratio = 100.0 * weight_sugar / (double)(weight_water+weight_sugar);
					if(ratio > max_ratio){
						max_ratio = ratio;
						water = weight_water;
						sugar = weight_sugar;
					}
				}
			}
		}
	}
	cout << water+sugar << " " << sugar << endl;
	return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		int m=s.nextInt();
		long x=s.nextInt();
		
		long[][] arr=new long[n][m];
		long[] cost=new long[n];
		
		for(int i=0;i<n;i++)
		{
			cost[i]=s.nextInt();
			
			for(int j=0;j<m;j++)
			{
				arr[i][j]=s.nextInt();
			}
		}
		
		long[] skill=new long[m];
		
		long c=fun(arr,cost,0,skill,n,m,0,x);
		
		if(c!=Long.MAX_VALUE)
			System.out.println(c);
		else
			System.out.println(-1);
		
	}
	
	public static long fun(long[][] arr,long[] cost,int curr,long[] skill,int n,int m,long c,long x)
	{
		if(curr==n)
		{
			int count=0;
			
			for(int i=0;i<m;i++)
			{
				if(skill[i]>=x)
				{
					count++;
				}
			}
			
			if(count==m)
				return c;
			else
			{
				return Long.MAX_VALUE;
			}
		}
		
		long[] temp1=new long[m];
		long[] temp2=new long[m];
		
		for(int i=0;i<m;i++)
		{
			temp1[i]=skill[i];
		}
		
		for(int i=0;i<m;i++)
		{
			temp2[i]=skill[i]+arr[curr][i];
		}
		
		long c1=fun(arr,cost,curr+1,temp1,n,m,c,x);
		long c2=fun(arr,cost,curr+1,temp2,n,m,c+cost[curr],x);
		
		return Math.min(c1,c2);
	}
	
}

Measured memory_bytes: 39720
#include <iostream>
 
int main(void) {
	int n;
  	std::cin >> n;
  	long double sum = 1, s;
  	std::cin >> s;
  	long double temp;
  	for(int i = 0; i < n-1; ++i){
    	std::cin >> temp;
      	sum += s / temp;
    }
  
  	sum = s / sum;
  	std::cout << sum << std::endl;
  
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#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++)
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i, N) {
    cin >> vec.at(i);
  }
  int co = 1;
  int co2 = 0;
  int con = 0;
  int coa = 0;
  while(true) {
    co2 = vec.at(co - 1);
    con++;
    vec.at(co - 1) = 0;
    co = co2;
    if(co2 == 0) {
      coa = 1;
      break;
    }
    if(co2 == 2) {
      break;
    }
  }
  if(coa == 1) {
    cout << -1 << endl;
  }
  else {
    cout << con << endl;
  }
}


Measured memory_bytes: 3780
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, c;
vector<int> s, t, ch;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>c;
    for (int i = 0; i < n; i++)
    {
        int temps, tempt, tempc;
        cin >> temps>>tempt>>tempc;
        s.push_back(temps);
        t.push_back(tempt);
        ch.push_back(tempc-1);
    }
    int sumc[100002][c];
    for(int i=0;i<=100001;i++){
        for(int j=0;j<c;j++)
            sumc[i][j]=0;
    }
    for(int i=0;i<n;i++){
        sumc[s[i]][ch[i]]++;
        sumc[t[i]+1][ch[i]]--;
    }
    int summ[100002][c];
    for(int j=0;j<c;j++){
        int sum=0;
    for(int i=0;i<=100001;i++){
        sum+=sumc[i][j];
        summ[i][j]=sum;
        }
    }
    int ans=0;
    for(int i=0;i<=100001;i++){
        int count=0;
        int sum=0;
        for(int j=0;j<c;j++){
            if(summ[i][j]>=1)  count++;
        }
        ans=max(ans,count);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 25068
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] s = new int[N];
        int sum = 0;
        for(int i=0; i<N; i++) {
            s[i] = Integer.parseInt(sc.next());
            sum += s[i];
        }
        Arrays.sort(s);
        
        if(sum % 10 == 0) {
            for(int i=0; i<N; i++) {
                if((sum-s[i]) % 10 != 0) {
                    sum -= s[i];
                    break;
                }
                if(i == N-1) {
                    sum = 0;
                }
            }
        }
        
        System.out.println(sum);
    }
    
}

Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        printf("%c", (s[i] - 65 + n) % 26 + 65);
    }
    printf("\n");
}


Measured memory_bytes: 256
#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 N;
  cin >> N;
  vector<int> S;
  rep(i, N){
    int s;
    cin >> s;
    S.push_back(s);
  }
  
  int ans = 0;
  for(int c: S){
    ans += (c-1);
  }

 cout << ans << endl;
}
   
      

    

   
      

Measured memory_bytes: 256
s=gets.chomp;
yy=s[0..1].to_i(10);mm=s[2..3].to_i(10);
if 1 <= mm && mm <= 12 && !(1 <= yy && yy <=12) then
puts :YYMM
elsif 1 <= yy && yy <= 12 && !(1 <= mm && mm <=12) then
puts :MMYY
elsif 1 <= yy && yy <= 12 && 1 <= mm && mm <= 12 then
puts :AMBIGUOUS
else
puts :NA
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define rep(i, s, e) for (auto i = s; i < e; i++)
#define peek(c)      \
	for (auto i : c) \
		cout << i << ' ';

void solve()
{
	ll e, m;
	cin >> e >> m;
	map<ll, set<ll>> mm;
	rep(i, 0, m)
	{
		ll x, y;
		cin >> x >> y;
		mm[x].insert(y);
	}
	for(auto i: mm[1])
	{
		for(int j: mm[i])
		{
			if(j == e)
			{
				cout << "POSSIBLE";
				return;
			}
		}
	}
	cout << "IMPOSSIBLE";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 28416
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
/**  '' "\n" ^ -  =**/

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    sf(n);
    vector<ll> a;
    ll x;
    in(i,n)
    {
        cin>>x;
        a.push_back(x);
    }
    a.push_back(111111111111);
    int step=0;
    stack<pair<ll,int> > s;
    for(int i=0;i<a.size();i++)
    {
        if(s.empty())
        {
            s.push({a[i],i});
            continue;
        }
        if(s.top().first>=a[i])
        s.push({a[i],i});
        else
        {
            while(!s.empty())
            {
                int id=i-s.top().second-1;
                step=max(step,id);
                //cout<<id;ps();cout<<s.top().first;ps();cout<<a[i]<<endl;
                s.pop();
            }
            s.push({a[i],i});
        }
    }
    cout<<step<<endl;
}


Measured memory_bytes: 2676
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
a,b,c,d= map(int, input().split())

while 1:
    c = c -b
    if (c <= 0):
        print("Yes")
        exit()
    a = a - d
    if (a <= 0):
        print("No")
        exit()




Measured memory_bytes: 9136
n=int(input())
f=0
for i in range(1,n+2):
	if i*(i-1)//2==n:
		f=1
		break
if f==0:
	print("No")
	exit()
print("Yes")
print(i)
k=i
cnt=0
s=[[-1]*k for _ in range(k)]
for i in range(k):
	for j in range(k):
		if i<j:
			s[i][j]=cnt
			cnt+=1
ans=[[]for _ in range(k)]
for i in range(k):
	for j in range(k):
		if s[i][j]!=-1:
			ans[i].append(s[i][j]+1)
			ans[j].append(s[i][j]+1)
for x in ans:
	print(k-1,*x)


Measured memory_bytes: 17360
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, m = LI()
    ans_ip = 0
    unit = (1/2)**m

    for i in range(1,10**5):
        p = (1-unit)**(i-1)*(unit)
        ans_ip+= i*p
    t = (n-m)*100 + m*1900

    ans= t*ans_ip
    ans = round(ans)
    print(ans)
main()


Measured memory_bytes: 69244
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	string S;
	cin >> S;
	int ans1, ans2;
	ans1 = 0;
	ans2 = 0;
	for (int i = 0; i < S.length(); i++) {
		if (i%2==0 && S[i] == '0') {
			ans1++;
		}
		if (i % 2 == 1 && S[i] == '1') {
			ans1++;
		}
	}
	for (int i = 0; i < S.length(); i++) {
		if (i % 2 == 0 && S[i] == '1') {
			ans2++;
		}
		if (i % 2 == 1 && S[i] == '0') {
			ans2++;
		}
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 512
N, K = map(int, input().split())
set_all = set()
for i in range(K):
    d = int(input())
    #assert d != 0, "お菓子は誰かが持っている必要があります"
    #すぬけ君1とすぬけ君3がお菓子を持っている
    li = map(int, input().split())
    set_li = set(li)
    #{1,3}
    set_all = set_all | set_li

s = {i for i in range(1,N+1,1)}
s_xor = s ^ set_all
print (len(s_xor))

Measured memory_bytes: 9184
#include<iostream>
int main(){
  
  int a,b;
 std::cin>>a>>b;
  
  if(a>=13){
    std::cout<<b<<std::endl;
  }else if(a<=5){
    std::cout<<0<<std::endl;
  }else{
   std::cout<<b/2<<std::endl;
  }
     
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char s[200020];
  char t[200020];
  int i,k=0;
  scanf("%s %s",s,t);
  for(i=0;s[i]!='\0';i++){
  if(s[i]!=t[i]) k++;
  }
  printf("%d",k); 
  
 return 0; 
}


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

int main() {
	
  int count = 0;
    vector<char> a(3);
    vector<char> b(3);
    rep(i, 3){
        cin >> a.at(i);
    }
    rep(i, 3){
        cin >> b.at(i);
        if(a.at(i) == b.at(i)) count++;
    }
    cout << count << endl;

}

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

using namespace std;

void test_case()
{
    int n,k;
    cin>>n>>k;
    int n2=n-1;
    long long now=n+1,ans=0;
    if(k<=1) ans+=now;
    //cout<<ans<<"\n";
    for(int i=1;i<=(n);i++){
        now+=((long long)n2-(long long)i);
        n2--;
        if(i+1>=k){
            ans+=now;
            ans = ans%1000000007LL;
        }
        //cout<<now<<"\n";
    }
    cout<<ans<<"\n";
}

int main()
{
        test_case();

    return 0;
}


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

const int maxn = 1e5 + 10;
typedef long long int ll;
bool cmp(ll a,ll b){
	return a > b;
}
ll a[maxn],b[maxn],c[maxn],st[maxn];
void solved(){
	ll x,y,A,B,C;cin>>x>>y>>A>>B>>C;
	for(int i = 1; i <= A; i++)cin>>a[i];
	for(int i = 1; i <= B; i++)cin>>b[i];
	for(int i = 1; i <= C; i++)cin>>c[i];
	sort(a + 1, a + 1 + A,cmp);
	sort(b + 1, b + 1 + B,cmp);
	sort(c + 1, c + 1 + C,cmp);
	ll ans = 0;
	priority_queue<ll,vector<int>,greater<int> >st;
	for(int i = 1; i <= x; i++){
		st.push(a[i]); ans += a[i];
	}
	for(int i = 1; i <= y; i++){
		st.push(b[i]);ans += b[i];
	}
	for(int i = 1; i <= C;i++){
		if(c[i] > st.top()){
			ans-=st.top();
			st.pop();
			ans+=c[i];
		}else break;
	}
	cout<<ans<<endl;
}
int main(){
	solved();
	return 0;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;

int main(){
  cin >> n;
  for(lli i = 0;;i++){
    lli x = i;
    lli y = 0;
    for(lli s = 1;x != 0;s*=4){
      if(x%2 == 1) y += s;
      x /= 2;
    }
    x = n+y*2;
    if(x < 0) continue;
    x /= 2;
    for(;x != 0;){
      if(x%2 == 1) break;
      x /= 4;
    }
    if(x == 0){
      x = n+y*2+y*2;
      vll out;
      if(x == 0){
        cout << 0 << endl;
        return 0;
      }
      for(;x != 0;){
        out.push_back(x%2);
        x /= 2;
      }
      reverse(out.begin(),out.end());
      for(lli c : out){
        cout << c;
      }
      cout << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    string s,t;
    int cnt = 0;
    cin >> s;
    cin >> t;
    

    for(int i=0;i<3;i++){
       if(s[i] == t[i]){ 
         cnt++;
       }
    }
   cout << cnt << endl;
}



Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
n = 0
for x in (a, b, c, d, e,):
    n += -(-x // 10)*10
k = 10
for i in (a, b, c, d, e):
    j = i % 10
    if j != 0 and k > j:
        k = j
print(n - 10 + k)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char c[2][3];
    int i,j;
    for(i=0;i<2;i++)
    for(j=0;j<3;j++)
    cin>>c[i][j];

    if((c[0][0]==c[1][2])&&(c[0][1]==c[1][1])&&(c[0][2]==c[1][0]))
    cout<<"YES";
    else 
    cout<<"NO";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool b[14][14];
int r[]={-1,0,0,1}, l[]={0,1,-1,0};

int func(int a[14][14], int x, int y){
	if(a[x][y] == 0 || a[x][y] == -1 || b[x][y])return 0;
	b[x][y] = true;
	for(int i = 0;i < 4;i++)func(a, x+r[i], y+l[i]);
}

int main(){
	int a[14][14];
	string s;
	
	while(cin >> s){
		if(s == "")cin >>s;
		fill((int*)a, (int*)(a+14), -1);
		fill((int*)b, (int*)(b+14), 0);
		int ans = 0;
		
		for(int i = 1;i <= 12;i++){
			if(i != 1)cin >> s;
			for(int j = 1;j <= 12;j++)a[i][j] = s[j-1]-'0';
		}
		
		for(int i = 1;i <= 12;i++){
			for(int j = 1;j <= 12;j++){
				if(!b[i][j] && a[i][j]){func(a, i, j);ans++;}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  vi a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  int cnt = 0;
  while (a[1] < a[2]) {
    a[0]++;
    a[1]++;
    cnt++;
  }
  while (a[0] < a[1]) {
    a[0] += 2;
    cnt++;
  }
  if (a[0] == a[1]) cout << cnt << endl;
  else cout << cnt + 1 << endl;
}

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

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

    int i;
    for(i = 1;; i++){
        if(i*(i+1) >= 2*n)  break;
    }

    int useless = i*(i+1)/2 - n;
    for(int j = 1; j <= i; j++){
        if(j != useless)    cout << j << endl;
    }

    return 0;
}

Measured memory_bytes: 256