akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        QuickScanner in = new QuickScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }
}

class Task {
    public void solve(QuickScanner in, PrintWriter out) {
        int D = in.nextInt();
        int T = in.nextInt();
        int S = in.nextInt();
        double time = (double)D/(double)T;
        if(T*S >= D) {
        	out.print("Yes");        	
        }else {
        	out.print("No");
        }
    }
}
class TaskB {
    public void solve(QuickScanner in, PrintWriter out) {
        char[] S = in.next().toCharArray();
        char[] T = in.next().toCharArray();
        int ans = T.length;
        for(int start = 0; start <= S.length - T.length; start++) {
        	int diff = 0;
        	for(int i = 0; i < T.length; i++) {
        		if(T[i] != S[start + i]) {
        			diff++;
        		}
        	}
        	ans = Math.min(ans,diff);
        }
        out.print(ans);
    }
}


class QuickScanner {
    BufferedReader in;
    StringTokenizer token;
    String delim;
    public QuickScanner(InputStream inputStream)
    {
        this.in=new BufferedReader(new InputStreamReader(inputStream));
        this.delim=" \n\t";
        this.token=new StringTokenizer("",delim);
    }

    public boolean hasNext()
    {
        while(!token.hasMoreTokens())
        {
            try {
                String s=in.readLine();
                if(s==null) return false;
                token=new StringTokenizer(s,delim);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return true;
    }

    public String next()
    {
        hasNext();
        return token.nextToken();
    }

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

}


Measured memory_bytes: 32884
// Why all solutions are wrong?
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N=9e5+5,mo=1e9+7;

typedef long long LL;

int n,m,K,ans,Fac[N],Inv[N],p[N];

int C(int n,int m)
{
    return (LL)Fac[n]*Inv[m]%mo*Inv[n-m]%mo;
}

int main()
{
    p[0]=Fac[0]=Inv[0]=Fac[1]=Inv[1]=1; p[1]=3;
    for (int i=2;i<N;i++) Inv[i]=(LL)Inv[mo%i]*(mo-mo/i)%mo;
    for (int i=2;i<N;i++)
    {
        p[i]=p[i-1]*3ll%mo; Fac[i]=(LL)Fac[i-1]*i%mo; Inv[i]=(LL)Inv[i-1]*Inv[i]%mo;
    }
    scanf("%d%d%d",&n,&m,&K); n--;
    if (m<K) swap(m,K);
    for (int i=0,j=1;i<=m+K;i++)
    {
        ans=(ans+(LL)C(n+i,n)*p[m+K-i]%mo*j)%mo;
        if (i<K) j=j*2%mo;
        else if (i>=m) j=(j*2ll-C(i,K)-C(i,i-m))%mo;
        else j=(j*2ll-C(i,K))%mo;
    }
    if (ans<0) ans+=mo;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 10752
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

N = gets_i
s_list = gets_nsp_list

MOD = 10**9 + 7

s_count = s_list.group_by(&:itself).map{|k,v| v.count + 1 }
puts (s_count.inject(&:*) - 1) % MOD


Measured memory_bytes: 8572
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    A, B, C, D = iim()

    def cnt(a, b):
        c, d = divmod(a, b)
        if d:
            c += 1
        return c

    a1 = cnt(C, B)
    a2 = cnt(A, D)
    print("Yes" if a1 <= a2 else "No")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9176
#include <stdio.h>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;

int main(){
    int k;
    scanf("%d", &k);

    int n;
    if(k == 1){
        printf("1\n1");
        return 0;
    }else if(k % 4 != 0){
        n = (k / 4 + 1) * 2;
    }else{
        n = k / 2;
    }

    int c[500][500];

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i % 2 == 0){
                c[i][j] = (i + j) % n;
            }else{
                c[i][j] = (i + j) % n + n;
            }
            if(c[i][j] >= k){
                c[i][j] -= n;
            }
        }
    }

    printf("%d\n", n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(j < n - 1){
                printf("%d ", c[i][j] + 1);
            }else{
                printf("%d\n", c[i][j] + 1);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 2048
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val instr = readLine.split(" ").head
    val alphabet = "abcdefghijklmnopqrstuvwxyz"
    val ans = alphabet.filterNot(e => instr.contains(e))

    println( if(ans != "") ans.head else "None" )
  }
}


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

int n, A[100100];

int partition(int p, int r) {
    int x = A[r];
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

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

    int idx = partition(0, n - 1);
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        if (i == idx) {
            cout << "[" << A[i] << "]";
            continue;
        }
        cout << A[i];
    }
    cout << endl;
    return 0;
}


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

template <class T1> void write(T1 e)
{
    cout << e << endl;
}
template <class T1,class T2> void write(T1 e1,T2 e2)
{
    cout << e1 << " "<< e2 << endl;
}
template <class T1,class T2,class T3> void write(T1 e1,T2 e2,T3 e3)
{
    cout << e1 << " " << e2 << " " << e3 << endl;
}

#define oo          (1<<30)
#define SZ(a)       (int)a.size()
#define LL          long long int
#define ULL         unsigned long long
#define ISS         istringstream
#define OSS         ostringstream
#define VS          vector <string>
#define VI          vector <int>
#define VD          vector <double>
#define VLL         vector <long long>
#define SII         set<int>::iterator
#define SI          set<int>
#define mem(a,b)    memset(a,b,sizeof(a))
#define fs          first
#define sc          second
#define pii         pair < int , int >

#define EQ(a,b)     (fabs(a-b)<ERR)
#define all(a,b,c)  for(int I=0;I<b;I++)    a[I] = c
#define CROSS(a,b,c,d) ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
#define sqr(a)      ((a)*(a))
#define FORE(i,a)   for(typeof((a).begin())i=(a).begin();i!=(a).end();i++)
#define BE(a)       a.begin(),a.end()
#define RBE(a)      a.rbegin(),a.rend()
#define rev(a)      reverse(BE(a));
#define sorta(a)    sort(BE(a))
#define pb          push_back
#define popb        pop_back
#define Round(i,a)  i = ( a < 0 ) ? a - 0.5 : a + 0.5;

#define makeint(n,s)  istringstream(s)>>n
#define string_to_int(str) atoll(str.c_str());

#define LCM(A,B)    ((__gcd(A,B))/A)*B
#define GCD(A,B)     __gcd(A,B)

#define YES     write("YES")
#define Yes     write("Yes")
#define yes     write("yes")
#define NO      write("NO")
#define No      write("No")
#define no      write("no")

#define read()      freopen("test.txt","r",stdin)
#define write_file()     freopen("WA.txt", "w", stdout);
#define Faster      {ios_base::sync_with_stdio(false); cin.tie(0);}

#define PI          3.141592653589793
#define pi          2*acos(0)
#define gama        0.57721566490
#define ERR         1e-5
#define PRE         1e-8
#define MAX         1000009

#define Scan(A)         scanf("%lld", &A)
#define Scan2(A, B) 	scanf("%lld %lld",&A, &B)
#define Scan3(A, B, C) 	scanf("%lld %lld %lld",&A, &B, &C)
#define Scan4(A, B, C, D) 	scanf("%lld %lld %lld %lld",&A, &B, &C, &D)

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

bool isvowel(char ch)
{
    ch = tolower(ch);
    return ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u';
}

struct myStruct
{
    LL Sum;
    string name;
    string Party;
};

bool cmp(myStruct a, myStruct b)
{
    return a.Sum > b.Sum ? 0 : 1;
}

map <char, int> Mp;

void Method()
{
    int j = 0;
    for(char i = 'a'; i <= 'z'; i++)
    {
        char temp = (char) i;
        Mp[temp] = j;
        j++;
    }
}

int main()
{
    LL M;
    while(cin >> M)
    {
        write(48-M);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;

int main (){
    int H,A;
    cin >> H >> A;
    int ans=0;

    while(true){
        H = H-A;
        ans +=1;
        if (H<=0){
            break;
        }
    }

    cout << ans;
    
}

Measured memory_bytes: 256
//om namah shivaaay//
#include <bits/stdc++.h>
#define Om_namah_Shivaay ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
 #define ll long long
 using namespace std;
 int main()
 {
    Om_namah_Shivaay;
 int n;
 scanf("%d",&n);
 long long ans=0;
 for(int i=1;i<=n;i++){
 if(i%3!=0 && i%5!=0)ans+=i;
 }
 printf("%lld\n",ans);
}


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

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

template<class T> inline bool chmax(T& a , T b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
const long long INF=1LL<<60;

int N;

long long h[100010][3];
long long dp[100010][3];

int main(){
  cin >> N;
  int a[N],b[N],c[N];
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      cin >> h[i][j];
    }
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k) continue;
        chmax(dp[i+1][k],dp[i][j]+h[i][k]);
      }
    }
  }

  long long res=0;
  for(int j=0;j<3;j++) chmax(res,dp[N][j]);
  cout << res << endl;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <vector>
#include <queue>
#define INF (1LL<<60)
using namespace std;

typedef long long Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for(auto &f:g[e.dst]) {
      if (dist[f.dst] > e.weight+f.weight) {
        dist[f.dst] = e.weight+f.weight;
        Q.push(Edge(f.src, f.dst, e.weight+f.weight));
      }
    }
  }
}

int main(){
	int i,V,E,start,goal,s,t,e;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d",&V);
		Graph g(V);
		for(i=0;i<V-1;i++)scanf("%d%d%d",&s,&t,&e),g[s-1].push_back(Edge(s-1,t-1,e)),g[t-1].push_back(Edge(t-1,s-1,e));
		scanf("%d%d",&e,&start);
		vector<Weight> dist;
		vector<int> prev;
		shortestPath(g,start-1,dist,prev);
		for(i=0;i<e;i++){
			scanf("%d%d",&s,&t);
			printf("%lld\n",dist[s-1]+dist[t-1]);
		}
	//}
}

Measured memory_bytes: 11504
using System;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int S = int.Parse(Console.ReadLine());
            int second = 0;
            int m = 0;
            int h = 0;

            second = S % 60;
            m = (S / 60) % 60;
            h = (S / 60) / 60;


            Console.WriteLine($"{h}:{m}:{second}");
            Console.ReadLine();
        }
    }
}



Measured memory_bytes: 17900
#include <cstdio>
#include <algorithm>
using namespace std;
int N, M, L = 1, R = 1e5;
int main() {
  scanf("%d %d", &N, &M);
  for(int i = 0, l, r; i < M; ++i) {
    scanf("%d %d", &l, &r);
    L = max(L, l);
    R = min(R, r);
  }
  printf("%d\n", R-L+1>0?R-L+1:0);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define mp make_pair
int main()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	int dp[n];
	for(int i=2;i<n;i++)
	dp[i]=INT_MAX;
	dp[0]=0;
	dp[1]=abs(arr[0]-arr[1]);
	for(int i=2;i<n;i++)
	{
		for(int j=1;j<=k;j++)
		if(i>=j)
		dp[i]=min(dp[i],dp[i-j]+abs(arr[i-j]-arr[i]));
		
	}
	cout<<dp[n-1]<<endl;
	return 0;
}
  


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N),pos(N);
  rep(i,N) {
    cin >> A[i];
    A[i]--;
    pos[A[i]]=i;
  }
  multiset<int> s;
  s.insert(-1);
  s.insert(-1);
  s.insert(pos[N-1]);
  s.insert(N);
  s.insert(N);
  ll ans = 0;
  drep(k,N-1) {
    auto r = s.lower_bound(pos[k]);
    auto l = prev(r);
    auto nr = next(r);
    auto nl = prev(l);
    ll a = 1ll*(*l-*nl)*(*r-pos[k]);
    ll b = 1ll*(*nr-*r)*(pos[k]-*l);
    ans += (a+b)*(k+1);
    s.insert(pos[k]);
  }
  cout << ans << endl;
  return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T & ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T & ref, const T value) {
    if (ref < value) ref = value;
}

struct edge {
    int from;
    int to;
    ll cost;
    edge(){}
    edge(int a, int b, ll c) : from(a), to(b), cost(c){}
};

struct UnionFind {
public:
    vector <ll> par; // 
    vector <ll> siz; // 

    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }

    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

struct KruskalRunner {
    static bool orderByCost(const edge& e1, const edge& e2) {
        return e1.cost < e2.cost;
    }

    ll solve(int vCount, vector<edge>& edges) {
        sort(edges.begin(), edges.end(), orderByCost);
        UnionFind uf = UnionFind(vCount);
        ll sum = 0;
        for (int i = 0; i < edges.size(); ++i) {
            edge e = edges[i];
            if (!uf.issame(e.from, e.to)) {
                uf.merge(e.from, e.to);
                sum += e.cost;
            }
        }
        return sum;
    }
};

int main() {

    ll n;
    cin >> n;
    vector<P> xs(n);
    vector<P> ys(n);
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        xs[i] = { x, i };
        ys[i] = { y, i };
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    vector<edge> edges;
    for (int i = 0; i < n-1; i++) {
        edges.emplace_back(xs[i].second, xs[i + 1].second, xs[i + 1].first - xs[i].first);
        edges.emplace_back(ys[i].second, ys[i + 1].second, ys[i + 1].first - ys[i].first);
    }
    KruskalRunner r;
    ll sum = r.solve(n, edges);
    cout << sum << endl;
    return 0;
}



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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int m, f, r;
    vector<map<string, int>> data;
    while(true){
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1) break;
        map<string, int> d = {{"m",m}, {"f",f}, {"r",r}};
        data.push_back(d);
    }

    rep(i, data.size()){
        int mr = data[i]["m"] + data[i]["f"];
        if(data[i]["m"] == -1 || data[i]["f"] == -1) cout << "F" << endl;
        else if(mr >= 80) cout << "A" << endl;
        else if(mr >= 65) cout << "B" << endl;
        else if(mr >= 50) cout << "C" << endl;
        else if(mr >= 30) {
            if(data[i]["r"] >= 50) cout << "C" << endl;
            else cout << "D" << endl;
        }
        else cout << "F" << endl;
    }
}



Measured memory_bytes: 3240
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=505;
int n,m,f[MAXN][MAXN];
int ans,Ans[MAXN*MAXN][5];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&f[i][j]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++)
			if(f[i][j]%2==1){
				f[i][j]--;
				f[i][j+1]++;
				ans++;
				Ans[ans][1]=i;
				Ans[ans][2]=j;
				Ans[ans][3]=i;
				Ans[ans][4]=j+1;
			}
		if(f[i][m]%2==1&&i!=n){
			f[i][m]--;
			f[i+1][m]++;
			ans++;
			Ans[ans][1]=i;
			Ans[ans][2]=m;
			Ans[ans][3]=i+1;
			Ans[ans][4]=m;
		}
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d %d %d\n",Ans[i][1],Ans[i][2],Ans[i][3],Ans[i][4]);
	return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k, x, y, ans = 0;
	
	cin >> n >> k >> x >> y;
	
	if(n > k){
		ans = k*x + (n-k)*y;
		cout << ans;
		
		return 0;
	}
	
	ans = x*n;
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 3512
#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;
int main(){
	int a, b, c;
	cin>>a>>b>>c;
	cout<<a+b+c-max(max(a,b),c); 
	return 0;
}

Measured memory_bytes: 256
n = int(input())
c = list(input())
r = [0]
w = [0]
for i in range(n):
    if c[i] == "W":
        w.append(w[-1]+1)
    else:
        w.append(w[-1])
    if c[i] == "R":
        r.append(r[-1]+1)
    else:
        r.append(r[-1])

ans = float('inf')
for i in range(n+1):
    r_left = r[i]
    r_right = r[-1] - r[i]
    w_left = w[i]
    w_right = w[-1] - w[i]
    
    ans = min(ans,max(r_right,w_left))

print(ans)

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

int main(){
    long long X,K,D,ans;
    cin >> X >> K >> D;
    X=abs(X);
    if(K<=(X/D)){
        ans=(X-(K*D));
    }else{
        K=(K-(X/D));
        if(K%2==0){
            ans=(X%D);
        }else if(K%2==1){
            ans=abs((X%D)-D);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
H, W, K = [int(i) for i in input().split()]

validBit = []
for i in range(1<<(W-1)):
    valid = True
    for j in range(W-1):
        if ((i>>j)&1) == 1 and ((i>>(j+1))&1) == 1:
            valid = False
    if valid:
        validBit.append(i)

mod = 1000000007
dp = [[0] * W for i in range(H+1)]
dp[0][0] = 1

for i in range(H):
    for j in range(W):
        if dp[i][j] == 0:
            continue
        for k in validBit:
            nj = j
            if ((k >> j) & 1) == 1:
                nj = j + 1
            elif j > 0 and (k >> (j-1) & 1) == 1:
                nj = j - 1

            dp[i+1][nj] = (dp[i+1][nj] + dp[i][j])%mod

ans = dp[H][K-1]
print(ans)
                             
            


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve(){
    int n,x; cin>>n>>x;
    int l[n+1],i; l[0]=0;
    for (i = 1; i <= n; ++i)
    {
        cin>>l[i];
        l[i]+=l[i-1];
        if(l[i]>x)
            break;
    }
    cout<<i;
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            out.println((n - 1) * (m - 1));
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



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

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

int main()
{
	string s;
	cin >> s;
	int n = 3;
	bool A = false;
	rep(i,n){
		if(s[i] == 'A'){
			A = true;
		}
	}
	rep(i,n){
		if(A){
			if(s[i] == 'B'){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3584
import heapq


def main():
    n, m = map(int, input().split(' '))
    a_s = list(sorted(map(lambda x: -1 * int(x), input().split(' '))))

    heapq.heapify(a_s)
    for _ in range(m):
        e = heapq.heappop(a_s)
        heapq.heappush(a_s, int(e/2))
    print(-1*sum(a_s))
    
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 14180
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  if(n%2) {
    cout<<"No"<<endl;
    return 0;
  }
  bool ok=true;
  for(int i:irange(0,n/2)) {
    if (s[i] != s[i+n/2]) ok = false;
  }
  if (ok) {
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }
  return 0;
}


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

const int MOD=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll s=0;
  ll ans=0;
  for(int i=0;i<n;++i){
    cin >> a[i];
    s+=a[i];
    s%=MOD;
  }

  for(int i=0;i<n;++i){
    s-=a[i];
    if(s<0)s+=MOD;

    ans+=a[i]*s;
    ans%=MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4852
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

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

	if ((c + b - 1) / b <= (a + d - 1) / d) yn

	return 0;
}

Measured memory_bytes: 3636
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    long N = S.length;
    long K = lread();
    auto dp = new long[][][](2, 4, N + 1);
    // N以下確定か否か、0でない数字使用回数、処理する位置
    dp[0][0][N] = 1;
    foreach_reverse (i; 0 .. N)
    {
        long s = S[N - i - 1] - '0';
        dp[s != 0][3][i] += dp[0][3][i + 1];
        dp[1][3][i] += dp[1][3][i + 1];
        foreach (j; 0 .. 3)
        {
            if (s == 0)
            {
                dp[1][j + 1][i] += dp[1][j][i + 1] * 9;
                dp[1][j][i] += dp[1][j][i + 1];

                dp[0][j][i] += dp[0][j][i + 1];
            }
            else
            {
                dp[1][j + 1][i] += dp[1][j][i + 1] * 9;
                dp[1][j][i] += dp[1][j][i + 1];

                dp[0][j + 1][i] += dp[0][j][i + 1]; // sを使う
                dp[1][j][i] += dp[0][j][i + 1]; // 0を使う
                dp[1][j + 1][i] += dp[0][j][i + 1] * (s - 1); // それ以外
            }
        }
    }
    // writeln(dp[0][K][0]);
    // writeln(dp[1][K][0]);
    writeln(dp[0][K][0] + dp[1][K][0]);
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int n,flag,m1,m2,m3,m4;
  scanf("%d",&n);
  m1=n/1000;
  m2=n/100-m1*10;
  m3=n/10-n/100*10;
  m4=n%10;
  if(m2==m3 && (m1==m2 || m3==m4))
  {
    flag=1;
  }
  else
  {
    flag=0;
  }
  if(flag)
  {
    printf("Yes\n");
  }
  else
  {
    printf("No\n");
  }
  return 0;
}


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

using namespace std;

int main()
{
    int n, a, b;
    int cnt = 0;
    int focn = 0;
    string re;

    cin >> n >> a >> b >> re;

    for (int i = 0; i < n; i++) {
        if (re[i] == 'a') {
            if (cnt + focn < a+b) {
                cout << "Yes" << endl;
                cnt++;
            }
            else {
                cout << "No" << endl;
            }
        }
        else if (re[i] == 'b') {
            if (cnt + focn < a+b && focn < b) {
                cout << "Yes" << endl;
                focn++;
            }
            else {
                cout << "No" << endl;
            }
        }
        else {
            cout << "No" << endl;
        }
    }
}


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

int main()
{
    int n, flag = 1, a[110] = {0};
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i] % 2 == 0 && flag)
        {
            if(a[i] % 3 == 0 || a[i] % 5 == 0) flag = 1;
            else flag = 0;
        }
    }
    if(flag) printf("APPROVED\n");
    else printf("DENIED\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

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

	vector<int> d(n);
	rep(i,0,n) cin >> d[i];
	sort(all(d));
	cout << d[n/2] - d[n/2-1]<< endl;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

int n; string ans; 
bool ask(vector<int> a){
    printf("? ");
    rep(i,0,n)printf("%d ",a[i]);
    puts(""); fflush(stdout);
    string s; cin>>s;
    return s[0]=='R';
}

int main(){
    scanf("%d",&n);
    rep(i,0,2*n)ans+='?';
    vector<int> a(n); iota(ALL(a),1);
    bool f=ask(a); int lb=1,rb=n+1;
    while(rb-lb>1){
        int mid=(lb+rb)/2; iota(ALL(a),mid);
        if(ask(a)!=f)rb=mid; else lb=mid;
    }
    vector<int> b(n-1); if(n!=1)iota(ALL(b),rb);
    rep(i,1,2*n+1){
        if(n==1||i<b[0]||i>b.back()){
            vector<int> c=b; c.push_back(i);
            if(ask(c))ans[i-1]='R';
            else ans[i-1]='B';
        }
    }
    int rcnt=0,bcnt=0; a.clear();
    rep(i,0,2*n){
        if(ans[i]=='R'&&rcnt<n/2){
            a.push_back(i+1); rcnt++;
        }
        if(ans[i]=='B'&&bcnt<n/2){
            a.push_back(i+1); bcnt++;
        }
    }
    rep(i,lb,lb+n-1){
        vector<int> c=a; c.push_back(i+1);
        if(ask(c))ans[i]='R'; else ans[i]='B';
    }
    cout<<"! "<<ans<<endl; fflush(stdout);
    return 0;
}

Measured memory_bytes: 724
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int a, b;
  readf (" %d %d", &a, &b);
  foreach (s; 0 .. 1_000_000) {
    int x = (s * 8) / 100;
    if (x != a) continue;
    int y = s / 10;
    if (y != b) continue;
    writeln (s);
    return;
  }
  writeln (-1);
}



Measured memory_bytes: 256
N = int(input())

# c[i][j]: 先頭の桁の数がiで、末尾の桁の数がjとなる個数
c = [[0] * 10 for _ in range(10)]

for i in range(1,N+1):
    s = str(i)
    c[int(s[0])][int(s[-1])] += 1

ans = 0
# AとBは区別できる
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
    
print(ans)

Measured memory_bytes: 3064
N = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(N[K-1])

Measured memory_bytes: 3060
def check_h(x, y, xy_):
    difference_h = abs(x-xy_[0]) + abs(y-xy_[1])
    return difference_h

def main():
    n = int(input())
    xyh = [list(map(int, input().split())) for _ in range(n)]
    get_h = [xyh[i][2] for i in range(n)]
    X, Y, H = xyh[get_h.index(max(get_h))]

    for i in range(101):
        for j in range(101):
            xy = [i, j]
            h = H + check_h(X, Y, xy)
            if h >= H:
                if all(xyh[s][2]==max(h-check_h(xyh[s][0], xyh[s][1], xy), 0) for s in range(n)):
                    print(i, j, h)
                    break
    return 0

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int,int> pii;
struct Situation{
public:
  pii cost;
  int node;
  int rev;
  Situation(pii cost_,int node_,int rev_){
    cost=cost_;
    node=node_;
    rev=rev_;
  }
  Situation();
  bool operator<(const Situation &s)const{
    return s.cost<this->cost;
  }
};

const int INF=1000000000;
const int MAX_V=1001;

vector<int> G[MAX_V];
vector<int> revG[MAX_V];
pii d[MAX_V][2];
int EdgeNum[MAX_V][MAX_V];
pii prevv[MAX_V][2];
void dijkstra(int s){
  priority_queue<Situation> que;
  for(int i=0;i<MAX_V;i++){
    for(int j=0;j<2;j++){
      d[i][j].first=INF;d[i][j].second=0;
      prevv[i][j].first=prevv[i][j].second=-1;
    }
  }
  d[s][0].first=0;
  que.push(Situation(pii(0,0),s,0));
  while(que.size()){
    Situation p=que.top();que.pop();
    int node=p.node;
    pii cost=p.cost;
    int rev=p.rev;
    if(d[node][rev]<cost)continue;
    for(int i=0;i<G[node].size();i++){
      int to=G[node][i];
      if(d[to][rev].first>d[node][rev].first+1){
	d[to][rev].first=d[node][rev].first+1;
	d[to][rev].second=d[node][rev].second;
	que.push(Situation(d[to][rev],to,rev));
	prevv[to][rev]=pii(node,rev);
      }
      // 一致する場合
      else if(d[to][rev].first
	      ==d[node][rev].first+1){
	if(d[to][rev].second>d[node][rev].second){
	  d[to][rev].second=d[node][rev].second;
	  que.push(Situation(d[to][rev],to,rev));
	  prevv[to][rev]=pii(node,rev);
	}
      }
    }
    if(!rev){
      for(int i=0;i<revG[node].size();i++){
	int to=revG[node][i];
	if(d[to][rev^1].first>d[node][rev].first+1){
	  d[to][rev^1].first=d[node][rev].first+1;
	  d[to][rev^1].second=EdgeNum[to][node];
	  que.push(Situation(d[to][rev^1],to,rev^1));
	  prevv[to][rev^1]=pii(node,rev);
	}
	else if(d[to][rev^1].first
		==d[node][rev].first+1){
	  if(d[to][rev^1].second>EdgeNum[to][node]){
	    d[to][rev^1].second=EdgeNum[to][node];
	    que.push(Situation(d[to][rev^1],to,rev));
	    prevv[to][rev^1]=pii(node,rev);
	  }
	}
      }
    }
  }
}

int N,M;
int S,T;
int main(){

  while(cin>>N&&N){
    for(int i=0;i<N;i++){
      G[i].clear();
      revG[i].clear();
    }
    cin>>S>>T;
    S--;T--;
    cin>>M;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	EdgeNum[i][j]=INF;
    for(int i=0;i<M;i++){
      int a,b;
      cin>>a>>b;
      a--;b--;
      G[a].push_back(b);
      revG[b].push_back(a);
      EdgeNum[a][b]=min(EdgeNum[a][b],i+1);
      EdgeNum[b][a]=min(EdgeNum[b][a],i+1);
    }
    dijkstra(S);
    pii res=min(d[T][0],d[T][1]);
    cout<<res.first<<" "<<res.second<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 5240
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

// ai == ajとなるi, jは、ai+1...aj-1を反転した結果と同じになるため無視してOK
// ai != ajについて、ai...ajを反転したものをb(i,j)と考えた場合、
// b(i,j)がaと文字が異なる最左位置はiであり、同様に文字が異なる最右位置はjとなる。
// b(i,j) = b(x,y)と仮定すると。b(x,y)がaと文字が異なる最左位置はiになるためx=i,
// 同様に最右位置はjになるためy=jとなる。よって、b(i,j) = b(x,y)であれば、i=xかつj=yが成立する。
// 対偶(pならばq　→　qでなければpでない)をとると、i!=x またはj !=yであればb(i,j) != b(x,y)となる。
// よって、ai != ajなるi..jを反転して得られた文字列は全て異なる。
// 上記より、ai != ajなるi<jの組を数え上げ、その組＋1（初期文字列）と計算することで解が得られる。
int main(){
    Init();
    string s; cin >> s;
    ll n = s.size();
    map<char, ll> cnt;
    rep(i, n) cnt[s[i]]++;

    // 全ての組み合わせからai == ajなる組を除く。
    ll ans = n*(n-1)/2;
    for(char c='a'; c<='z'; c++){
        if(cnt[c] <= 1) continue;
        ans -= (cnt[c]*(cnt[c]-1))/2;
    }
    // 元々の文字列分を1個足す
    cout << ans+1 << endl;
}

Measured memory_bytes: 3764
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,N,bf=1,sum=0,ans=0,res=0;
  cin>>N;
  vec v(N);
  rep(i,N){
    cin>>v[i];
    sum+=v[i];
    if(bf*sum<=0){
      ans+=labs(sum)+1;
      sum=bf;
    }
    bf*=-1;
  }

  bf=-1;
  sum=0;
  rep(i,N){
    sum+=v[i];
    if(bf*sum<=0){
      res+=labs(sum)+1;
      sum=bf;
    }
    bf*=-1;
  }
  chmin(ans,res);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
//AtCoder Beginner Contest 149
//B - Greedy Takahashi

#include <iostream>

using namespace std;

int main()
{
    long long  a, b, k;

    cin >> a >> b >> k;

    if (a >= k) {
        cout << a - k << " " << b << endl;
    }else{
        cout << 0 << " " << (b - (k - a) < 0 ? 0 : b - (k - a))<< endl;
    }

    return 0;
}


Measured memory_bytes: 256
def abc050_c():
  n = int(input())
  A = list(map(int, input().split()))
  div = 10**9 + 7

  from collections import Counter
  cntr = Counter(A)

  if n % 2 == 0:
    # 偶数個の場合：1,3,5..が2個ずつ
    for i in range(1, n, 2):
      if cntr[i] != 2:
        print(0)
        return
  else:
    # 奇数個の場合：0が1個、2,4,6..が2個ずつ
    if cntr[0] != 1:
      print(0)
      return
    for i in range(2, n, 2):
      if cntr[i] != 2:
        print(0)
        return

  # 半分決まれば残り半分は自動的に決まる
  # nを2で切り捨てた個数 (奇数個のど真ん中は含まない)
  ans = pow(2, n//2, div)
  print(ans)

abc050_c()

Measured memory_bytes: 14180
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

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

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int mass[120];
int main(){
    CIN(N);CIN(M);CIN(X);
    I vec;
    REP(a,M){
        CIN(b);
        mass[b]=1;
    }
    int ans1 = 0,ans2=0;
    for(int a = X;a < N-1;a++){
        ans1+=mass[a+1];
    }
    for(int a = X;a != 0;a--){
        ans2+=mass[a-1];
    }
    COUT(min(ans1,ans2));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<long long int>
#define vc vector<char>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(i = (a); i < (n); i++)
#define fi(i,a,n) for(i = (a); i <= (n); i++)
#define F first
#define S second
int main() {
    ll k,n;
    cin>>k>>n;
    ll x = (n-k+1);
    if(x<(-1000000)){
        x = -1000000;
    }
    ll y = (n+k-1);
    if(y>(1000000)){
        y = 1000000;
    }



    for(ll i=x;i<=y;i++){
        cout<<i<<" ";
    }

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(b: str):
    if b == 'A':
        ret = 'T'
    elif b == 'T':
        ret = 'A'
    elif b == 'C':
        ret = 'G'
    elif b == 'G':
        ret = 'C'
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    b = next(tokens)  # type: str
    solve(b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
using System;
class ProgramC
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            
            int min = 0;
            int max = 1250;
            int temp = 0;
            
            //二分探索法。
            while(max != min + 1)
            {
                //とりあえず真ん中の数でそれより大きいか小さいかを探す
                temp = (max + min) /2;
                
                //実際の金額を求めて、満たすなら最小、満たさないなら最大にする
                if((int)(temp * 0.08) < a || (int)(temp * 0.1) < b)
                    min = temp;
                else
                    max = temp;

            }
            
            //答え出力
            if((int)(max * 0.08) == a && (int)(max * 0.1) == b)
                Console.WriteLine(max);
            else
                Console.WriteLine("-1");

        } 
    }

Measured memory_bytes: 13140
def multival(): return map(int,input().split())
def data(N=1): return [list(map(int,input().split())) for _ in range(N)]
mod = 10**9 + 7
inf = float("inf")


N,M = multival()
nemat = [[0]*N for _ in range(N)]
ans = M
info = []
for _ in range(M):
    a,b = multival()
    a -= 1; b-= 1
    nemat[a][b] = 1
    nemat[b][a] = 1
    info.append([a,b])

def dfs(now,visited):
    visited[now] = True
    if all(visited):
        global ans
        ans -= 1
        return
    for ne in range(N):
        if nemat[now][ne] == 1 and visited[ne] is False:
            dfs(ne,visited)
    
for i,j in info:
    nemat[i][j] = 0
    nemat[j][i] = 0
    dfs(0,[False]*N)
    nemat[i][j] = 1
    nemat[j][i] = 1

print(ans)

Measured memory_bytes: 3064
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n;
    cin>>n;
    vec a(n),b(n),c(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];
    
    sort(all(a));
    sort(all(b));
    sort(all(c));

    ll ans = 0;
    rep(i,n){
        ll num1 = lower_bound(all(a), b[i]) - a.begin();
        ll num2 = c.end() - upper_bound(all(c),b[i]);
        ans+=num1*num2;
    }

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

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

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

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

int main() {
	int N;
	cin >> N ;
	vector<int>A(N);
	for (int n = 0;n<N;++n) {
		cin >> A[n];
	}
	int ans = 0;	
	for (int n = 0; n < N; ++n) {
		ans = gcd(A[n],ans);
	}
	cout << ans;
}


Measured memory_bytes: 3712