akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template<class T>inline void read(T &res)
{
    char c;
    T flag=1;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
    res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';
    res*=flag;
}
void gcd(ll a,ll b,ll &d,ll &x,ll &y)
{
    if(!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        gcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}
ll in(ll a,ll mod)
{
    ll d,x,y;
    gcd(a,mod,d,x,y);
    return d==1?(x+mod)%mod:-1;
}

ll qp(ll a,ll x,ll mod)
{
    ll ans=1;
    while(x)
    {
        if(x%2==1)
            ans=(ans*a)%mod;
        a=(a*a)%mod;
        x/=2;
    }
    return ans;
}
int cmp(ll a,ll b)
{
    return a<b;
}

ll hang[300005],lie[300005];
int phang[300005],k=0,plie[300005],kk=0;
set<pair<int,int> > st;
int main()
{
    ll t1=0,t2=0,ans;
    int h,w,m,x,y,pi,pj,ii;
    read(h);
    read(w);
    read(m);
    for(int i=0;i<m;i++)
    {
        read(x);
        read(y);
        st.insert(make_pair(x,y));
        hang[x]++;
        lie[y]++;
    }
    for(int i=1;i<=h;i++)
    {
        if(t1<hang[i])
        {
            pi=i;
            t1=hang[i];
        }
    }
    for(int i=1;i<=h;i++)
    {
    	if(hang[pi]==hang[i])
    		phang[k++]=i;
	}
	for(int i=1;i<=w;i++)
	{
		if(t2<lie[i])
		{
			pj=i;
			t2=lie[i];	
		} 
	}
	for(int i=1;i<=w;i++)
	{
		if(lie[pj]==lie[i])
			plie[kk++]=i;
	} 
    for(int i=0;i<kk;i++)
    {
		int f=0;
		for(ii=0;ii<k;ii++)
		{
			if(st.count(make_pair(phang[ii],plie[i]))==0)
				{
					pi=phang[ii];
					pj=plie[i];
            		f=1;
            		break;
				}
		}
		if(f)
		{
            t2=lie[plie[i]];
            break;
		}
		//}

    }
    ans=t1+t2;
    if(st.count(make_pair(pi,pj)))
        ans--;
    cout<<ans<<endl;
    return 0;

}



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

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

ll n, m, k;

const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i, a) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

  int main() {
    cin >> n >> m >> k;
    combination c(n);

    mint ans = 0;
    mint col = m;
    for (int x = n - 1; x >= 0; --x) {
      mint now = col;
      now *= c(n - 1, x);
      if (x <= k) ans += now;
      col *= m - 1;
    }
    cout << ans.x << endl;
    return 0;
  }


Measured memory_bytes: 6336
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdint>
#include <algorithm>
#include <iterator>
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define repeat(i,n) repeat_from(i,0,n)
using namespace std;
enum we_t { W, E };
template <typename It>
void step(vector<string> const & s, map<pair<int,we_t>,vector<pair<int,we_t> > > const & g, It it) {
    int x = s.size();
    repeat (i,x) {
        repeat (n,s[i].size()+1) {
            string l = s[i].substr(0, n);
            string r = s[i].substr(n);
            for (we_t p : { W, E }) {
                if ((l.empty() and p == W) or (r.empty() and p == E)) continue;
                auto v = make_pair(i,p);
                for (auto w : g.at(v)) {
                    int  j = w.first;
                    we_t q = w.second;
                    vector<string> t = s;
                    t[i]     = p == W ? r : l;
                    string u = p == W ? l : r;
                    if (p == q) reverse(u.begin(), u.end());
                    t[j] = q == W ? u + s[j] : s[j] + u;
                    *(it ++) = t;
                }
            }
        }
    }
}
map<vector<string>,int> steps(vector<string> const & s, map<pair<int,we_t>,vector<pair<int,we_t> > > const & g, int n) {
    map<vector<string>,int> ms;
    ms[s] = 0;
    vector<vector<string> > vs;
    vs.push_back(s);
    repeat (i,n) {
        vector<vector<string> > ws;
        for (auto it : vs) {
            step(it, g, back_inserter(ws));
        }
        vs.clear();
        for (auto it : ws) {
            if (not ms.count(it)) {
                ms[it] = i+1;
                vs.push_back(it);
            }
        }
    }
    return ms;
}
int main() {
    while (true) {
        int x, y; cin >> x >> y;
        if (x == 0 and y == 0) break;
        map<pair<int,we_t>,vector<pair<int,we_t> > > g;
        repeat (i,x) for (we_t j : { W, E }) g[make_pair(i,j)];
        repeat (i,y) {
            char p, P, q, Q; cin >> p >> P >> q >> Q;
            auto a = make_pair(p - '0', P == 'W' ? W : E);
            auto b = make_pair(q - '0', Q == 'W' ? W : E);
            g[a].push_back(b);
            g[b].push_back(a);
        }
        vector<string> s(x); repeat (i,x) { cin >> s[i]; if (s[i] == "-") s[i].clear(); }
        vector<string> t(x); repeat (i,x) { cin >> t[i]; if (t[i] == "-") t[i].clear(); }
        map<vector<string>,int> s2 = steps(s, g, 2);
        map<vector<string>,int> t2 = steps(t, g, 2);
        int result = 6;
        for (auto it : s2) {
            if (t2.count(it.first)) {
                result = min(result, it.second + t2[it.first]);
            }
            if (it.second == 2) {
                vector<vector<string> > s3;
                step(it.first, g, back_inserter(s3));
                for (auto that : s3) {
                    if (t2.count(that)) {
                        result = min(result, 1 + it.second + t2[that]);
                    }
                }
            }
        }
        cout << result << endl;
    }
    return 0;
}

Measured memory_bytes: 4828
N, M = gets.chomp.split.map(&:to_i) # N個のスイッチ, Mの電球
a = []
c = []
M.times do |_m|
  g = gets.split.map(&:to_i)
  c << g[0] # 電球に紐づくスイッチの個数
  a << [*g[1..-1]] # 電球に紐づくスイッチ
end
b = gets.split.map(&:to_i) # i番目の電球が、紐づくスイッチのうちONのものを2で割ってこれに一致したら、点灯する
count = 0
[true, false].repeated_permutation(N) do |sw| # arrには, M 個の {T, F}の組み合わせ
  count += 1 if a.map.with_index { |aa, aai| sw.select.with_index { |_s, i| aa.include?(i + 1) }.select { |s| s }.size % 2 == b[aai] }.all? { |a| a }
end
p count


Measured memory_bytes: 3964
k, n = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n-1):
  x = a[i+1] - a[i]
  b.append(x)
b.append(k - a[n-1] + a[0])
c = max(b)
print(k - c)

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

int N;


int len(int x) {
    int res = 0;
    while (x) {
        res++;
        x = x/10;
    }
    return res;
}

int solve() {
    int res = 0;
    FOR (i, 1, N+1) {
        if (len(i)&1) res++;
    }
    return res;
}

int main() {
    cin >> N;
    cout << solve() << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine
import scala.concurrent.duration.DurationInt

object Main {
  def main(args: Array[String]) {
    val input = readLine().toInt
    val convertSeconds = input.seconds
    val convertMinutes = convertSeconds.toMinutes.toInt
    val convertHours = convertSeconds.toHours

    val hours = convertHours.toInt
    val minutes = convertMinutes.toInt - hours * 60
    val seconds = input - hours * 60 * 60 - minutes * 60

    println(s"$hours:$minutes:$seconds")
  }
}

Measured memory_bytes: 43936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
	int n;
	cin >> n;
	string s;
	int cnt = 0;
	int reds = 0;
	for(int i=0; i<n; i++){
		cin >> s;
		if(s[i] == 'R')reds++;
	}
	for(int i=0; i<reds; i++){
		if(s[i] == 'W')cnt++;
	}
	cout << cnt << "\n";
	return 0;
}




Measured memory_bytes: 3732
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

using pii = pair<int64_t, int64_t>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
// }}} End

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int H, W; cin >> H >> W;

    for (size_t i = 0; i < H; ++i) {
        string s; cin >> s;
        cout << s << "\n" << s << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lef(x) (x<<1)
#define rig(x) (lef(x)+1)
#define int long long
const ll MOD=1e9+7LL;
const int N=200100;
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    ll rs=0LL,r=0,x,y,init=0;
    for (int i = 0; i < n; ++i)
    {
    	cin>>x>>y;
    	while(y > 1)
    	{
    		if(y%2==1)
    		{
    			r+=x;
    			if(init)
    				rs++;
    			init=1;
    			while(r>=10)
    			{
    				rs++;
    				r=r/10 +r%10;
    			}
    		}
			rs+=y/2;
			x+=x;
			if(x>=10)
			{
				rs+=y/2;
				x=x/10 +x%10;
			}
			y/=2;
    	}
    	// cout<<x<<" "<<y<<"\n";
    	r+=x;
    	if(init)
			rs++;
		init=1;
    	while(r>=10)
		{
			rs++;
			r=r/10 +r%10;
		}
    }
    cout<<rs<<"\n";
    return 0;   
}

Measured memory_bytes: 256
z=require('fs').readFileSync('/dev/stdin','utf8').trim().split(/\s/);
for(i=0;i<z.length;){
    a=z[i++];
    b=z[i++];
    c=z[i++];
    d=z[i++];
    e=z[i++];
    f=z[i++];
    y=(c*d-a*f)/(b*d-a*e);
    x=(c-b*y)/a;
    console.log((Math.round(x*=1000)/1000).toFixed(3)+" "+(Math.round(y*=1000)/1000).toFixed(3));
}

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

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i=0; i<n; ++i){
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	int a=n/2;
	cout << v[a]-v[a-1];
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define sum(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class BCraneAndTurtle {
public:
  static void solve(istream &cin, ostream &cout) {
    int X, Y;
    cin >> X >> Y;
    rep(i, 101) {
      rep(j, 101) {
        if (i + j == X and 2 * (i) + 4 * (j) == Y) {
          cout << "Yes" << endl;
          return;
        }
      }
    }
    cout << "No" << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  BCraneAndTurtle solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

// 入力
int n, W;
int weight[110], value[110];

// DPテーブル
int dp[110][10010];

int main() {
  cin >> n >> W;
  for (int i = 0; i < n; ++i) cin >> value[i] >> weight[i];

  // DP初期条件: dp[0][w] = 0
  for (int w = 0; w <= W; ++w) dp[0][w] = 0;

  // DPループ
  for (int i = 0; i < n; ++i) {
    for (int w = 0; w <= W; ++w) {
      if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

  cout << dp[n][W] << endl;
}



Measured memory_bytes: 7068
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b = LS()
    if a > b:
        return '>'
    if a < b:
        return '<'

    return '='


print(main())




Measured memory_bytes: 6480
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;

int main() {
  int a,b; cin >> a >> b;
  rep(i,20){
    if((a-1)*i+1>=b){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = map(int,input().split())
d = dict()
res = 0
for i in a:
  res += i
  if i not in d:
    d[i] = 1
  else:
    d[i] += 1

q = int(input())
for i in range(q):
  b, c = map(int,input().split())
  if b in d:
    x = d[b]
    res += (c - b) * x
    if c not in d:
      d[c] = x
    else:
      d[c] += x
    d[b] = 0
  print(res)


Measured memory_bytes: 85912
s = input()
l = len(s)
okey = 1
ll = l//2

for i in range(0,l//2):
    if s[i] != s[l-i-1]:
        okey = 0
        break

if okey == 1: 
    for i in range(0,ll//2):
        if s[i] != s[ll-i-1]:
            okey = 0
            break

if okey == 1:
    for i in range(ll+1, ll+ll//2):
        if s[i] != s[l-i-1]:
            okey = 0
            break

if okey == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9112
words = lambda t : list(map(t, input().split()))
n = int(input())
a = words(int)

ans = 0
for i in range(n-2):
    if (a[i] < a[i+1] and a[i+1] < a[i+2]) or a[i] > a[i+1] and a[i+1] > a[i+2]:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int m[1000001];
int main(){
  int x,y;
  while((x = getInt()) + (y = getInt())){
    memset(m, 0, sizeof(int) * y);
    for(int i=1; ; i++){
      if(x == 0){
	printf("%d %d\n",i-1, 0);
	break;
      }
      if(m[x] == 0){
	m[x] = i;
	x = (x * 10) % y;
      }else{
	printf("%d %d\n",m[x]-1, i - m[x]);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4740
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, K) = read!(usize, i64);
    let mut A = read![[i64]];
    A.sort();
    let mut s = 0;
    let mut k = 0;
    for a in A {
        if a + s > K {
            break;
        }
        s += a;
        k += 1;
    }
    if k == N && s != K {
        k -= 1;
    }
    println!("{}", k)
}


Measured memory_bytes: 4352
N = int(input())
for i in range(int(N / 4) + 1):
    for j in range(int(N / 7) + 1):
        if i * 4 + j * 7 == N :
            print("Yes")
            exit()
        if i * 4 + j * 7 > N :
            break
print("No")


Measured memory_bytes: 2940
#include <stdio.h>
#include <math.h>

#define M_PI 3.141592653589793


int main(void) {

	int i, j, k;
	int m, n, l;
	long sum;
	int A[100][100] = { 0 };
	int B[100][100] = { 0 };

	scanf("%d %d %d", &n, &m, &l);
	for (j = 0; j < n; j++) {
		for (i = 0; i < m; i++) {
			scanf("%d", &A[j][i]);
		}
	}
	for (j = 0; j < m; j++) {
		for (i = 0; i < l; i++) {
			scanf("%d", &B[j][i]);
		}
	}


	for (j = 0; j < n; j++) {
		for (i = 0; i < l; i++) {
			sum = 0;
			for (k = 0; k < m; k++) {
				sum += A[j][k] * B[k][i];
			}
			if (i != l - 1)			printf("%ld ", sum);
			else					printf("%ld", sum);
		}
		printf("\n");
	}
	

	return 0;

}

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

using namespace std;

int main() {
    int N, pre=0, p=0;
    scanf("%d", &N);

    string s;
    cin>>s;
    for(int i=0; i!=N; i++){
        if(s[i]=='('){
            p++;
        }else{
            if(p==0){
                pre++;
            }else p--;
        }
    }

    string rst = string(pre, '(') + s + string(p, ')');
    cout<<rst<<endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <sstream>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

string s;
int pos;


map<PI,int> t2i;
map<int,PI> i2t;

int get(int a,int b){
  if(t2i.count(mp(a,b)))
    return t2i[mp(a,b)];
  int n = t2i.size();
  i2t[n] = mp(a,b);
  return t2i[mp(a,b)] = n;
}

int parse(){
  if(s[pos] == 'x'){
    ++pos;
    return -1;
  }
  ++pos;
  int a = parse();
  ++pos;
  int b = parse();
  ++pos;
  if(a<b) swap(a,b);
  return get(a,b);
}

set<int> dfs(int p){
  set<int> ret;
  ret.insert(p);
  if(p>=0){
    assert(i2t.count(p));
    for(auto i : dfs(i2t[p].first)) ret.insert(i);
    for(auto i : dfs(i2t[p].second)) ret.insert(i);    
  }
  return ret;
}

PI rlsim(int a){
  if(a==-1) return mp(0,1);
  assert(i2t.count(a));
  set<int> app1=dfs(i2t[a].first);
  set<int> app2=dfs(i2t[a].second);
  set<int> app=app1;
  set<int> both;
  for(auto i : app2){
    app.insert(i);
    if(app1.count(i)) both.insert(i);
  }
  int c = both.size();
  if(c == 0) return mp(0,1);
  int p = app.size();
  int g=__gcd(c,p);
  return mp(c/g,p/g);
}


bool comp(int a,int b){// a < b
  PI asim = rlsim(a);
  PI bsim = rlsim(b);
  if(asim != bsim) return asim.first*bsim.second > bsim.first*asim.second;
  if(a<0 && b<0) return false;
  assert(i2t.count(a));
  assert(i2t.count(b));
  auto ac = i2t[a];
  auto bc = i2t[b];
  if(comp(ac.first, ac.second)) swap(ac.first, ac.second);
  if(comp(bc.first, bc.second)) swap(bc.first, bc.second);
  
  if(comp(ac.first, bc.first)) return true;
  if(comp(bc.first, ac.first)) return false;
  
  if(comp(ac.second, bc.second)) return true;
  return false;
}

void print(int p,bool le){
  le=!le;
  if(p>=0){
    auto pr = i2t[p];
    if(comp(pr.first, pr.second) ^ le) swap(pr.first, pr.second);
    
    cout <<"(";
    print(pr.first, true);
    cout << " ";
    print(pr.second, false);
    cout << ")";
  }else cout << "x";
}


int main(int argc, char *argv[])
{
  while(getline(cin,s) && s != "0"){
    pos = 0;
    print(parse(), true);
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,m; cin >> n >> m;
  int x = 100*(n-m)+m*1900;
  REP(i,m) x*=2;
  COUT(x);
  return 0;
}

Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-13 12:11:29
**/

#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n; string s; cin >> s;

  int64 ans = 0;

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (s[i] == s[j]) continue;
      for (int k = j + 1; k < n; ++k) {
        if (s[j] != s[k] && s[i] != s[k] && j - i != k - j) ++ans;
      }
    }
  }

  cout << ans << '\n';

  return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[45][2]; // i桁目までで、k以下であるかがjという状態の

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,k; cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  memset(dp,-1,sizeof(dp));
  dp[41][0]=0;
  
  for(ll i=40; i>=0; i--) rep(j,2){
    ll now=k>>i&1;
    rep(nxt,2){
      if(now<nxt && j==0) continue;
      if(dp[i+1][j]==-1) continue;
      ll nj=j|(nxt<now);
      ll sum=0;
      rep(l,n){
        if((a[l]>>i&1)==0 && nxt==1) sum++;
        if((a[l]>>i&1)==1 && nxt==0) sum++;
      }
      chmax(dp[i][nj],dp[i+1][j]+(sum<<i));
    }
  }
  
  ll ans=max(dp[0][0],dp[0][1]);
  cout<<ans<<endl;
  
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
main()

{
    char a[10005];
   unsigned long long int i,j,sum=0;
    for(j=0;j==0;)
    {
    scanf("%s",a);
    if(strcmp(a,"0")==0) break;
    for(i=0;a[i]!='\0';i++)
    {
        sum=sum+(a[i]-'0');
    }
    printf("%llu\n",sum);
    sum=0;
    }
}



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

int n;
long long A[100001];

int main(){
	cin>>n;
	int neg=0;
	long long lo=1000000001;
	long long ans=0;
	for(int i=1;i<=n;i++){
		cin>>A[i];
		if(A[i]<0){
			neg++;
		}
		lo=min(lo, abs(A[i]));
		ans+=abs(A[i]);
	}
	if(neg%2==0){
		cout<<ans<<endl;
	}else{
		cout<<ans-lo-lo<<endl;
	}
	
}

Measured memory_bytes: 1024
N, K = map(int, input().split(' '))
A = sorted(list(map(int, input().split(' '))))
mod = 10 ** 9 + 7
p = 0
for i in range(N):
    if A[i] >= 0:
        break
p = i
if (p == N - 1 and K % 2 != 0):
    ans = 1
    for i in range(K):
        ans *= A[-1 - i]
        ans %= mod
    print(ans%mod)
    exit()
minus = A[:p]
plus = sorted(A[p:],reverse=True)
len_m = len(minus)
len_p = len(plus)
m = 0
p = 0
ans = 1
while K > 0:
    if K >= 2 and m <= len_m - 2 and p <= len_p - 2:
        if minus[m] * minus[m+1] >= plus[p] * plus[p + 1]:
            ans *= minus[m] * minus[m + 1]
            ans %= mod
            m += 2
        else:
            ans *= plus[p] * plus[p + 1]
            ans %= mod
            p += 2
        K -= 2
    elif K >= 2 and m <= len_m - 2:
        ans *= minus[m] * minus[m + 1]
        ans %= mod
        m += 2
        K -= 2
    elif K >= 2 and p <= len_p - 2:
        ans *= plus[p] * plus[p + 1]
        ans %= mod
        p += 2
        K -= 2
    elif p <= len_p - 1:
        ans *= plus[p]
        ans %= mod
        p += 1
        K -= 1
    else:
        ans *= minus[m]
        ans %= mod
        m += 1
        K -= 1
print(ans%mod)


Measured memory_bytes: 31740
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

int H, W;
char a[10][10] = {};
int b[10][10] = {};
void dfs(int x, int y, int c) {
	if (a[x][y] == '.')return;
	b[x][y] = max(b[x][y], c);
	int dx[2] = { 1,0 };
	int dy[2] = { 0,1 };
	for (int i = 0; i < 2; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		dfs(nx, ny, c + 1);
	}
}

signed main() {
	cin >> H >> W;
	int sharp = 0;
	rep(i, 0, 10)rep(j, 0, 10)a[i][j] = '.';
	rep(i, 1, H + 1)rep(j, 1, W + 1) {
		cin >> a[i][j];
		if (a[i][j] == '#')sharp++;
	}
	dfs(1, 1, 1);
	if (b[H][W] == sharp)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 384
from sys import stdin, stdout
from time import perf_counter

import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7

# import sys
# sys.stdout = open("e:/python/cp/output.txt","w")
# sys.stdin = open("e:/python/cp/input.txt","r")

l = sorted([int(item) for item in input().split()])
print("YES" if l == [5,5,7] else "NO")


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
 
 
int main(){
  int n;
  cin>>n;
  
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  
  sort(a.begin(), a.end(), greater<int>());
  
  ll ans=0;
  int j=-1;
  rep(i,n){
    j++;
    if(i==0) continue;
    if((i)%2) j--;
  	ans += a[j];
    //cout<<j<<endl;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 4044
x, y = map(int, input().split())
A = {1,3,5,7,8,10,12}
B = {4,6,9,11}
C = {2}
if (x in A and y in A) or (x in B and y in B) or (x in C and y in C):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
def tenka1bc19_c():
    N = int(input())
    S = str(input())

    # 白と黒の累積個数
    wt = [0]
    bk = [0]
    for s in S:
        w, b = wt[-1], bk[-1]
        if s == '.': w += 1
        else: b += 1
        wt.append(w)
        bk.append(b)

    # i番目までを白にして、i+1番目以降を黒にするときのコスト
    ans = 10**9
    for i in range(N+1):
        flip = bk[i] + wt[-1] - wt[i]
        ans = min(flip, ans)
    print(ans)

tenka1bc19_c()

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

int main(){
    double N, K;
    cin >> N >> K;

    double probab = 0;

    for(int i = 1; i <= N; i++){
        int I = i;
        double p = 1/N;
        while(I < K){
            I *= 2;
            p /= 2;
        }
        probab += p;
    }

    cout << fixed << setprecision(10) << probab << endl;
}

Measured memory_bytes: 256
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
	
	public static void main(String[] args) throws IOException {
		final Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int K = sc.nextInt();
		
		long[] array = new long[N];
		for(int i = 0; i < N; i++){
			array[i] = sc.nextLong();
		}
		
		long[] in_prefix_sum = new long[N + 1];
		long[] ex_prefix_sum = new long[N + 1];
		for(int i = 0; i < N; i++){
			in_prefix_sum[i + 1] = array[i] + in_prefix_sum[i];
			ex_prefix_sum[i + 1] = Math.max(0, array[i]) + ex_prefix_sum[i];
		}
		
		long answer = 0;
		for(int first_offset = 0; first_offset <= (N - K); first_offset++){
			final int second_index = first_offset + K;
			
			final long first_sum  = ex_prefix_sum[first_offset];
			final long center_sum = Math.max(0, in_prefix_sum[second_index] - in_prefix_sum[first_offset]);
			final long last_sum   = ex_prefix_sum[N] - ex_prefix_sum[second_index];
			
			/*
			System.out.println(first_offset);
			System.out.printf("[0, %d) = %d\n", first_offset, first_sum);
			System.out.printf("[%d, %d) = %d\n", first_offset, second_index, center_sum);
			System.out.printf("[%d, %d) = %d\n", second_index, N, last_sum);
			//*/
			
			//System.out.println(first_sum + " " + center_sum + " " + last_sum);
			
			answer = Math.max(answer, first_sum + center_sum + last_sum);
		}
		
		System.out.println(answer);
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 29500
#include <stdio.h>
int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if (x < r || W < x + r || y < r || H < y + r) {
		printf("No\n");
 	} else {
		printf("Yes\n");
	}
	return 0;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);
#define ll long long
int main() 
{
    FAST;
    // IN;
    // OUT;
    int n;
    cin>>n;
    if(n%1000!=0)
        cout<<1000-n%1000;
    else
        cout<<"0";
    return 0;
}

Measured memory_bytes: 3648
h,w = map(int,input().split())
c = [[int(i) for i in input().split()] for _ in range(10)]
a = [[int(i) for i in input().split()] for _ in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0
mp = [c[i][1] for i in range(10)]
mp.append(0)
for i in range(h):
    for j in range(w): ans += mp[a[i][j]]
print(ans)

Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
    int x,y,i,j,a=0;
	scanf("%d%d", &x, &y);
	switch (x)
	{
		case 1: i = 300000; break;
		case 2: i = 200000; break;
		case 3: i = 100000; break;
		default : i = 0; break;
	}
	switch (y)
	{
		case 1: j = 300000; break;
		case 2: j = 200000; break;
		case 3: j = 100000; break;
		default : j = 0; break;
	}
	if ( x == 1 && y == 1 )
		a = 400000;
	printf("%d\n",j+i+a);
	
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
using ull = unsigned long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<long double,long double> point;
typedef complex<long double> Point;
const ll MAX = 3000;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x,m;
    cin >> n >> x >> m;
    vector<ll> done(100005,0);
    ll a = x,cnt = 0;
    done[a] = 0;
    while (true){
        a = a*a%m;
        if (done[a]){
            cnt++;
            break;
        }
        cnt++;
        done[a] = cnt;
    }
    ll sum = a,ans = x;
    ll s = a;
    while (true){
        s = s*s%m;
        if (s == a) break;
        sum += s;
    }
    ll len = cnt-done[a];
    if (n <= done[a]){
        rep(i,n-1){
            x = x*x%m;
            ans += x;
        }
        PRINT(ans);
        return 0;
    }
    else{
        rep(i,done[a]-1){
            x = x*x%m;
            ans += x;
        }
        n -= done[a];
        ans += sum*(n/len);
        n %= len;
        rep(i,n){
            ans += a;
            a = a*a%m;
        }
        PRINT(ans);
    }
}


Measured memory_bytes: 3988
def main():
    from sys import stdin

    readline = stdin.readline

    a,b,c,d=list(map(int,readline().rstrip().split()))

    l=list()

    l.append(a * c)
    l.append(a * d)
    l.append(b * c)
    l.append(b * d)

    print(max(l))

main()

Measured memory_bytes: 9168
#
# abc105 b
#
import unittest
from io import StringIO
import sys


def input():
    return sys.stdin.readline().rstrip()


def resolve():
    N = int(input())
    C = 4
    D = 7

    for i in range(N//C+1):
        for j in range(N//D+1):
            if i*C + j*D == N:
                print("Yes")
                exit()
    print("No")


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """11"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """40"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3"""
        output = """No"""
        self.assertIO(input, output)


if __name__ == "__main__":
    #unittest.main()
    resolve()


Measured memory_bytes: 5744
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  int n;cin >> n;
  map<string,int> mm;
  while(n--){
    string s;cin >> s;
    mm[s]++;
  } 
  cout << mm.size() << endl;
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 19412
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define sevensins ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define mod  1000000007
#define vect vector<long long int>
#define bins binary_search
#define vecti vector<int>::iterator
#define bitout __builtin_popcount
#define binsrch binary_search
int main() 
{sevensins
ll t,i,j,k,l,n,sum;

    cin>>n;
    
    ll a=n/500;
    
    sum=a*1000;
    
    //cout<<sum<<"\n";
    a=n%500;
    
    sum=sum+(a/5)*5;
    
    cout<<sum<<"\n";

return 0;
}


Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=3005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int dp[N][N];
int32_t main()
{
    IOS;
    int n,s;
    cin>>n>>s;
    int ar[n+1];
    for(int i=1;i<=n;i++)
    cin>>ar[i];
    dp[0][0]=2;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j+ar[i]<=s;j++)
        dp[i][j+ar[i]]=(dp[i-1][j]*power(2, mod-2, mod))%mod;
        for(int j=0;j<=s;j++)
        dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
        if(i!=n)
        {
            for(int j=0;j<=s;j++)
            dp[i][j]=(dp[i][j]*2)%mod;
        }
    }
    //print2d(dp,n,s);
    cout<<dp[n][s];
}


Measured memory_bytes: 74112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sArr = Console.ReadLine().Split(' ');
            int a = int.Parse(sArr[0]);
            int b = int.Parse(sArr[1]);

            if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else
            {
                Console.WriteLine("a == b");
            }

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 8824
#include "bits/stdc++.h"
using namespace std;

int main() {
    long long K, A, B;
    cin >> K >> A >> B;

    long long ans = 1;
    if (A + 1 >= B) {
        cout << K + 1 << endl;
    }
    else {
        if (K < A + 1) cout << K + 1 << endl;
        else {
            K -= A + 1;
            ans = B;
            if (K % 2 == 0) {
                ans += (B - A) * (K / 2);
            }
            else {
                ans += (B - A) * (K / 2) + 1;
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 256