akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;


unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,T,k,q;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const ll MAXN = 3001;

vl A,B,C;
vector<pii> ANS;

ll solve(ll l, ll r, vl &V, bool rev){
    if(l == r)return V[l];
    ll a = V[r];
    ll b = solve(l,r-1,V,1);
   // cerr << l << " " << r << " "<< rev << "  -  " << b << "\n";
    if(!rev){
        ANS.push_back({a,b});
        return a-b;
    }
    else{
        ANS.push_back({b,a});
        return b-a;
    }
}

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

    //freopen("input.txt","r",stdin);
   // freopen("autput.txt","w",stdout);

    ll a,b,c,d;

    cin >> n;
    ll mi = 0;
    rep(c1,0,n){
        cin >> a;
        mi += (a < 0);
        A.push_back(a);
    }
    sort(all(A));
    mi = max(mi,1ll);
    mi = min(mi, n-1);

    if(mi == 1){
        ll ans = solve(0,n-1,A,0);
        cout << ans << "\n";
        rep(c1,0,n-1){
            cout << ANS[c1].first << " " << ANS[c1].second << "\n";

        }
        return 0;
    }
    if(mi == n-1){
        reverse(all(A));
        ll ans = solve(0,n-1,A,1);
        cout << ans << "\n";
        rep(c1,0,n-1){
            cout << ANS[c1].first << " " << ANS[c1].second << "\n";

        }
        return 0;
    }

    rep(c1,1,mi+1){
        B.push_back(A[c1]);
    }
    C.push_back(A[0]);
    rep(c1,mi+1,n){
        C.push_back(A[c1]);
    }
    reverse(all(B));
    b = solve(0,sz(B)-1,B,0);
    c = solve(0,sz(C)-1,C,0);
    ANS.push_back({c,b});
    cout << c-b << "\n";
    rep(c1,0,n-1){
        cout << ANS[c1].first << " " << ANS[c1].second << "\n";
    }

    return 0;
}


Measured memory_bytes: 9332
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        long ans = 1;
        int[] num = new int[N+2];
        num[0] = 3;
        for (int i = 0; i < N; i++) {
            if (num[A[i]] == 0) {
                ans = 0;
                break;
            }

            ans *= num[A[i]];
            ans %= 1_000_000_007;;

            num[A[i]]--;
            num[A[i]+1]++;
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 50716
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::collections::HashSet; use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
use std::io::prelude::*;

use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn cnt_digits(mut n: i64) -> i64 {
    let mut digits = 0;
    while n > 0 {
        n /= 10;
        digits += 1;
    }
    digits
}

fn main() {
    let n: i64 = input();
    let mut ans = cnt_digits(n);
    let mut a = 1;
    while a * a <= n {
        if n % a == 0 {
            let b = n / a;
            let cur = max(cnt_digits(a), cnt_digits(b));
            if ans > cur {
                ans = cur;
            }
        }
        a+=1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll A,B;
  cin>>A>>B;
  ll N=gcd(A,B);
  
  ll ans=0,M=N;
  for(int i=2; i<=sqrt(N)+1; ++i){
    if(M%i==0){
      while(M%i==0) M/=i;
      ans++;
    }
  }
  if(M!=N && M>1) ans++;
  if(M==N) ans=1;
  if(N==1) ans=0;
  co(ans+1);
  return 0;
}

Measured memory_bytes: 3676
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        
        int buttonA = Integer.parseInt(line[0]);
        int buttonB = Integer.parseInt(line[1]);

        int ans = 0;
        if(buttonA > buttonB){
            ans += buttonA;
            buttonA--;
        }else{
            ans += buttonB;
            buttonB--;
        }

        if(buttonA > buttonB){
            ans += buttonA;
        }else{
            ans += buttonB;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

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

int main()
{
  cout << fixed << setprecision(10);
  int N,T;
  cin >> N >> T;
  vector<int> c(N),t(N);
  rep(i,N)
  {
    cin >> c[i] >> t[i];
  }
  int mi = 10000;
  rep(i,N)
  {
    if(t[i]<=T)
    {
      mi = min(mi,c[i]);
    }
  }
  if(mi<=1000)
  {
    cout << mi << endl;
  }
  else if (mi = 10000)
  {
    cout << "TLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define N 2000000

void maxHeapify(int A[],int j); 
void buildMaxHeap(int B[]);
void maxHeapInsert(int C[],int x);
void heapIncreaseKey(int D[],int m,int y);
int heapExtractMax(int E[]);

int n;
int s=1;//
int P[N];//

int main(){
	char com[20];
	int node[N];
	int i,key;
	n=1;

	while(1){
		scanf("%s",com);
		if(com[0]=='i'){
			scanf("%d",&key);
			maxHeapInsert(node,key);
		}
		else if(com[0]=='e'){
			if(com[1]=='x')heapExtractMax(node);
			else break;
		}
	}

	for(i=1;i<s;i++)printf("%d\n",P[i]);

	return 0;
}

void maxHeapify(int A[],int j){
	int left,right,largest,key;

	left=2*j;
	right=left+1;
	if(left<=n && A[left]>A[j])largest=left;
	else largest=j;

	if(right<=n && A[right]>A[largest])largest=right;


	if(largest!=j){
		key=A[j];
		A[j]=A[largest];
		A[largest]=key;
		maxHeapify(A,largest);
	}
}

void buildMaxHeap(int B[]){
	int i;
	for(i=n/2;i>0;i--)maxHeapify(B,i);
}

void maxHeapInsert(int C[],int x){
	n=n+1;
	C[n]=-1;
	heapIncreaseKey(C,n,x);
}
void heapIncreaseKey(int D[],int m,int y){
	int key;
	if(y<D[m])printf("error\n");
	D[m]=y;
	while(m>1 && D[m/2]<D[m]){
		key=D[m/2];
		D[m/2]=D[m];
		D[m]=key;
		m=m/2;
	}
}
int heapExtractMax(int E[]){
	int max;
	if(n<1)return -1;
	max=E[1];
	E[1]=E[n];
	n=n-1;
	maxHeapify(E,1);
	P[s]=max;//
	s++;//
	return max;
}

Measured memory_bytes: 7968
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
ll a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(c-a-b<0)
	{
		cout<<"No";
		return 0;
	}
	if(4*a*b<(c-a-b)*(c-a-b))
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;

    ll x=b-a;

    REP(m,n-1){
        if((n-1-m)*c-d*m <= x and x <= (n-1-m)*d-c*m){
            cout<<"YES"<<en;
            return;
        }
    }
    cout<<"NO"<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans = []
tmp = sum(a) - 2*sum([a[i] for i in range(1, n-1, 2)])
ans.append(tmp)
a.pop()
for x in a:
    tmp = 2*x - tmp
    ans.append(tmp)

print(*ans)

Measured memory_bytes: 14032
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;
typedef pair<int,int> P;

int main(){
    int n,a,v;
    priority_queue<P,vector<P> > que;

    cin>>n;

    while(n--){
        cin>>a>>v;
        que.push(P(v,a));
    }

    v=que.top().first;
    a=que.top().second;
    que.pop();

    while(!que.empty() && que.top().first==v){
        a=min(a,que.top().second);
        que.pop();
    }

    cout<<a<<" "<<v<<endl;

    return 0;
}

Measured memory_bytes: 1200
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll inf=(ll)1<<60;
struct edge{
	int t,next,rev;
	ll v;
}g[510001];
ll ans,flow;
int i,j,k,n,m,a[2101],h[2101],s,t,tot,q[2101],dis[2101];
void addedge(int x,int y,ll v){
	g[++tot].t=y;g[tot].next=h[x];h[x]=tot;g[tot].v=v;g[tot].rev=tot+1;
	g[++tot].t=x;g[tot].next=h[y];h[y]=tot;g[tot].v=0;g[tot].rev=tot-1;
}
bool bfs(){
	int i,j,l,r;
	for (i=1;i<=t;i++) dis[i]=0;
	dis[s]=1;q[1]=s;l=0;r=1;
	while (l<r){
		j=q[++l];
		for (i=h[j];i;i=g[i].next)
		 if (g[i].v&&!dis[g[i].t]){
		 	dis[g[i].t]=dis[j]+1;q[++r]=g[i].t;
		 	if (t==g[i].t) return 1;
		 }
	}
	return 0;
}
ll work(int x,ll low){
	int i,k;
	ll res=0;
	if (x==t) return low;
	for (i=h[x];i&&low;i=g[i].next)
	 if (dis[g[i].t]==dis[x]+1&&g[i].v){
		k=work(g[i].t,min(low,g[i].v));
		res+=k;g[i].v-=k;low-=k;g[g[i].rev].v+=k;
	 }
	return res;
}
int main(){
	while (scanf("%d",&n)!=EOF){
		s=n+1;t=s+1;memset(h,0,sizeof(h));tot=0;ans=0;
		for (i=1;i<=n;i++) scanf("%d",&a[i]);
		for (i=1;i<=n;i++){
			if (a[i]>0) addedge(i,t,a[i]),ans+=a[i];
			else if (a[i]<0) addedge(s,i,-a[i]);
			for (j=i;j<=n;j+=i) addedge(i,j,inf);
		}
		for (flow=0;bfs();){
			flow+=work(s,inf);
		}
		ans-=flow;
		printf("%lld\n",ans);
	}
	return 0;
}

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

namespace ABC_Training
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            bool yymm = MatchYYMM(s);
            bool mmyy = MatchMMYY(s);
            if (yymm && mmyy)
            {
                Console.WriteLine("AMBIGUOUS");
            }
            else if (yymm && !mmyy)
            {
                Console.WriteLine("YYMM");
            }
            else if (!yymm && mmyy)
            {
                Console.WriteLine("MMYY");
            }
            else
            {
                Console.WriteLine("NA");
            }
        }

        private static bool MatchMMYY(string s)
        {
            int mm = int.Parse(s) / 100;
            return MatchMM(mm);
        }

        private static bool MatchMM(int mm)
        {
            if (mm == 0 || mm > 12)
            {
                return false;
            }
            return true;
        }

        private static bool MatchYYMM(string s)
        {
            int mm = int.Parse(s) % 100;
            return MatchMM(mm);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<ll> &v) {
    std::for_each(v.begin(), v.end(), [](ll x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// xとyに足すのは
// xからroot yからrootという操作と同じ
//それぞれのnodeの登場回数が偶数ならよい
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    map<int, int> cnt;
    REP(i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        cnt[a[i]]++;
        cnt[b[i]]++;
    }
    for(auto tmp : cnt) {
        if(tmp.second % 2 == 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1e6;
const ll LINF = (ll)1e19;

using Graph = vector<vector<ll>>;

void add(Graph G, vector<ll> &cnt, ll a){
    queue<P> q;
    ll p;
    q.push(make_pair(0,0));
    while(!q.empty()){
        tie(p, a) = q.front(); q.pop();
        cnt[p] += a;
        for(ll i = 0; i < G[p].size(); i++){
            q.push(make_pair(G[p][i], cnt[p]));
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, Q;
    cin >> N >> Q;
    vector<ll> p(Q), x(Q);
    Graph G(N);
    vector<ll> cnt(N,0);
    REP(i, N-1){
        ll a, b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    REP(i, Q){
        ll p, x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }
    add(G, cnt, 0);
    REP(i, N){
        cout << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 26880
S = list(input())
T = list(input())
diff = len(S)-len(T)

count, best = 0, 0

for i in range(diff+1):
  
  s = S[i:]
  
  #print('s')
  #print(s)
  
  count = 0
  for j,k in zip(s,T):
    if j == k:
      count += 1
    if count > best:
      best = count

print(len(T)-best)

Measured memory_bytes: 9072
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct edge
{
    int y;
    edge * next;
};
edge * li[100005];
edge * new_edge()
{
    static edge a[200005];
    static int top=0;
    return &a[top++];
}
void inserts(int x,int y)
{
    edge * t=new_edge();
    t->y=y;
    t->next=li[x];
    li[x]=t;
}
void insert_edge(int x,int y)
{
    inserts(x,y);
    inserts(y,x);
}
int cnt1=0,cnt2=0;
int col[100005];
bool dfs(int x,int now_col=0)
{
    col[x]=now_col;
    if (now_col==1) cnt1++; else cnt2++;
    edge * t;
    bool flag=false;
    for (t=li[x];t!=0;t=t->next)
    {
        if (col[t->y]==-1)
        {
            if (dfs(t->y,now_col^1)) flag=true;
        }
        if (col[t->y]==col[x])
        {
            flag=true;
        }
    }
    return flag;
}
long long sum_ans=0;
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    memset(col,-1,sizeof(col));
    int n,m;
    scanf("%d%d",&n,&m);
    int i;
    for (i=0;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        x--;
        y--;
        insert_edge(x,y);
    }
    for (i=0;i<n;i++)
    {
        if (col[i]!=-1) continue;
        cnt1=0;
        cnt2=0;
        if (!dfs(i))
        {
            sum_ans+=(long long)cnt1*cnt2;
        }
        else
        {
            sum_ans+=(long long)(cnt1+cnt2)*(cnt1+cnt2-1)/2;
        }
    }
    sum_ans-=m;
    cout<<sum_ans<<endl;
    return 0;
}


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

int main() {
  int n,k,p1,ans = 100001;
  cin >> n >> k;
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    if(a == 1) p1 = i;
  }
  for(int i = 0;i < k;i++){
    int ut = p1-i,st = p1+k-i-1;
    if(ut < 0 || st >= n) continue;
    int preans = 1;
    if(ut == 0) preans += 0;
    else if(ut-1 == 0) preans += 1;
    else if((ut-1)%(k-1) != 0) preans += (ut-1)/(k-1)+1;
    else preans += (ut-1)/(k-1);
    if(st == n-1) preans += 0;
    else if((n-st-1)%(k-1) != 0) preans += (n-st-1)/(k-1)+1;
    else preans += (n-st-1)/(k-1);
    if(preans < ans) ans = preans;
  }
  if(ans == 55079) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
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;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void Eratosthenes(ll n,Array& arr) {

}

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

	ll n,k,r,s,p;
	cin>>n>>k>>r>>s>>p;
	string t;
	cin>>t;

	Array used(n,false);
	ll ans=0;
	REP(i,n){
		if(i-k>=0&&(t[i]==t[i-k])&&used[i-k]){
			continue;
		}
		used[i]=true;
		if(t[i]=='r'){
			ans+=p;
		}else if(t[i]=='s'){
			ans+=r;
		}else{
			ans+=s;
		}
	}

	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 1232
use proconio::*;
use proconio::marker::*;
use std::collections::*;
use std::cmp::*;
use std::ops::Bound::*;

#[fastout]
fn run() {
    input! {
        n: usize,
    }
    for _ in 0..n {
        print!("ACL");
    }
    println!();
}

fn main() {
    run();
}


Measured memory_bytes: 2156
import math
n=int(input())
li=[]
for x in range(2,int(math.sqrt(n))+1):
    if n%x==0:
        y=n//x
        walk=y+x-2
        li.append(walk)
    
if li==[]:
    print(n-1)
else:
    print(min(li))

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

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	ll sum = 0;
	cin >> n;
	for(int i =1; i<=n;i++){
		if( i%3 == 0 || i%5 == 0) continue;
		else sum+=i;
	}
	cout << sum;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

vector<pair<int, int>> g[N];
int bio[N];

void dfs(int u, int c) {
  bio[u] = c;
  for (const auto &p: g[u]) {
    if (bio[p.first]) continue;
    if (p.second) dfs(p.first, 1+!(c-1));
    else dfs(p.first, c);
  }
}

void solve() {
  int n; scanf("%d", &n);
  for (int i = 0, u, v, w; i < n-1; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    g[u-1].emplace_back(v-1, w%2);
    g[v-1].emplace_back(u-1, w%2);
  }
  dfs(0, 1);
  for (int i = 0; i < n; ++i) {
    printf("%d\n", bio[i]-1);
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 11680
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000007
#define ll long long
#define PI acos(-1)
#define mp make_pair
#define mod 1000000007
int main()
{
	int a,b;
	cin>>a>>b;
	int ans=a-b+1;
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include<iostream>
#include<deque>
using namespace std;
deque<bool> seen;
deque<deque<int>> v(100);
int k = 0;
int n,m;
void dfs(int number,int depth){
        seen[number] = true;
        if(depth == n) k++;
        for(auto j : v[number])if(!seen[j])dfs( j, depth + 1);
        seen[number] = false;      
}                
int main(void){
cin >> n >> m;

for(int i = 0; i < m; i++){
        int a,b;cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
        }
seen.assign(n + 1, false);
dfs(1, 1);

cout << k << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
#include <bits/stdc++.h>
int main(int argc, char const *argv[])
{
  int64_t n,a,b,c,d,ans;
  scanf("%ld%ld%ld",&n,&a,&b);
  c=n/(a+b);
  d=n%(a+b);
  if(a>d) ans=c*a+d;
  else ans=c*a+a;
  printf("%ld",ans);
  return 0;
}

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

int main() {
  int n,m,c;
  cin >> n>>m>>c;
  vector<int>b(m);
  rep(i,m){
    cin>>b.at(i);
  }
  int ans=0;
  rep(i,n){
    int ch=c;
    vector<int>a(m);
    rep(j,m){
      cin>>a.at(j);
      ch+=a.at(j)*b.at(j);
    }
    if(ch>0){
      ans++;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>


int main(){
  int A,B,C,X,Y;
  int count = 0;
  scanf("%d%d%d%d",&A,&B,&C,&X);
  for(int a=0;a<=A;a++){
    for(int b=0;b<=B;b++){
      for(int c=0;c<=C;c++){
        Y = 500*a + 100*b + 50*c;
        if(X==Y) count ++;
      }
    }
  }
  printf("%d\n",count);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> odd(100000+10);
vector<int> even(100000+10);


int main(){
  int N;
  vector<int> v;
  int sub;
  int odd_cnt,even_cnt;
  int ans;
  cin>>N;

  for (int i=0;i<N;i++){
      cin>>sub;
      v.push_back(sub);
  }
bool flag=false;
for(int i=1;i<N;i++){
    if(v[i]!=v[0]) flag=true;
    if(flag) break;
}

if(!flag){
    ans=N/2;
    cout<<ans<<endl;
    return 0;
}

for(int i=0;i<N;i+=2){
    odd[v[i]]++;
}
odd_cnt=*max_element(odd.begin(),odd.end());
vector<int>::iterator odd_ite=max_element(odd.begin(),odd.end());
size_t odd_index = distance(odd.begin(),odd_ite);

for(int i=1;i<N;i+=2){
    even[v[i]]++;
}
even_cnt=*max_element(even.begin(),even.end());
vector<int>::iterator even_ite=max_element(even.begin(),even.end());
size_t even_index = distance(even.begin(),even_ite);
bool judge=false;

if(odd_index!=even_index) judge=true;
if(judge){
    ans=N-odd_cnt-even_cnt;
    cout<<ans<<endl;
}
else{
 ans=N-odd_cnt;
 odd[odd_index]=0;
 even[even_index]=0;

 odd_cnt=*max_element(odd.begin(),odd.end());
 even_cnt=*max_element(even.begin(),even.end());

 int draw=max(odd_cnt,even_cnt);
 ans-=draw;
 cout<<ans<<endl;
}
}

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

int main() {

    int i,ii,j,k=0;
    int n,m;
    int a,b,c;
    int flag=0;
    int ans = 0;
    std::cin >> n>>m;
    int s[m][n];
    int p[m];
    for (i = 0; i < m; i++){
        std::cin >> k;
        for(ii=0;ii<n;ii++)s[i][ii]=0;
        for(j=0;j<k;j++){
            std::cin >> a;
            s[i][a-1]=1;
        }
    }
    for(i=0;i<m;i++)
    std::cin >> p[i];
    
     for (int bit = 0; bit < (1<<n); ++bit)
    {
        /* bit で表される集合の処理を書く */


        /* きちんとできていることを確認してみる */
        // bit の表す集合を求める
        int S[n];
        for (i = 0; i < n; i++) {
            if (bit & (1<<i))S[i]=1;
            else S[i]=0;
        }
        flag=0;
        for(j=0;j<m;j++){
            int sum=0;
            for(ii=0;ii<n;ii++){
                sum+=S[ii]*s[j][ii];
            }
            if (sum%2!=p[j]){flag++;}
        }
        if (flag==0) ans++;
    }
     std::cout << ans << std::endl;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
len = a.max.to_s(2).length

ans = 0
len.times do |l|
  base = 2 ** l
  n_1 = a.inject(0) { |acc, cur| acc + cur[l] }
  ans += (n - n_1) * n_1 * base
end
puts ans % 1000000007


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

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>v;
int main()

{
    ll n,m,ans,i,sum=0,j;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>m;
        v.push_back(m);
    }
    for(i=0;i<v.size();i++){
        for(j=i+1;j<v.size();j++){
            sum=sum+v[i]*v[j];
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K,N,b,ans;
  int max=0;
  cin>>K>>N;

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  for(int i=0;i<N-1;i++){
    int a=vec.at(i+1)-vec.at(i);
    if(a>max){
      max=a;
    }
  }
  int a=K-vec.at(N-1)+vec.at(0);
  if(a>max){
    max=a;
  }
  ans=K-max;
  cout<<ans<<endl;
  
}





Measured memory_bytes: 1024
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val A = readLine()!!.split(" ").map(String::toInt)
  var b = 1
  for (a in A) {
     if (a == b) {
        b++
     }
  }
  println(if(b!=1) n-b+1 else -1)                         
}

Measured memory_bytes: 82852
inf = 10**15
mod = 10**9+7


# nCr

def ruijo(n, l, mod):
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


def cmb(n, r, mod):
    if r == 1:
        return n
    elif (n == r or r == 0):
        return 1
    else:
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return ruijo(n, n - r + 1, mod) * g2[r] % mod


mod = 10 ** 9 + 7  # 出力の制限
N = 10 ** 6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n,m = map(int, input().split())
if m == 1:
    print(1)
else:
    bpre = factorization(m)
    ans = 1
    for tmp in bpre:
        b = tmp[1]
        ans *= cmb(n-1+b, n-1, mod)
        ans = ans%mod
    print(ans)

Measured memory_bytes: 128168
fn main() {
    let n: usize = read();
    let mut xs: Vec<usize> = vec![0;n];
    for i in 0..n {
        xs[i] = read();
    }

    xs.sort();
    xs.reverse();

    let mut a = 0;
    let mut b = 0;
    for i in 0..n {
        let x = xs[i];
        if i % 2 == 0 {
            a += x;
        } else {
            b += x;
        }
    }
    println!("{}", a - b);
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	string S;

	cin >> S;
	if (S[2] == S[3] && S[4] == S[5])
		puts("Yes");
	else
		puts("No");
}


Measured memory_bytes: 256
#include<stdio.h>
int gcd(int a,int b){
	while(a){
		b%=a;
		int c=a;
		a=b;
		b=c;
	}
	return b;
}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int c;scanf("%d",&c);
		a=gcd(a,c);
	}
	if(a!=1){
		printf("No\n");
	}else printf("Yes\n");
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            int[] list = { sc.nextInt(), sc.nextInt(), sc.nextInt() };
            Arrays.sort(list);
            System.out.println(list[0] * list[0] + list[1] * list[1] == list[2] * list[2] ? "YES" : "NO");
        }
        sc.close();
    }
}


Measured memory_bytes: 33452
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();

    ll n;
    cin >> n;
    
    ll ans = 0;
    
    for (ll i = sqrt(n); i >= 1; -- i) {
    	if (n % i == 0) {
    		ans = i + (n / i) - 2;
    		break;
    	}
    }
    
    cout << ans;
    cout << '\n';
    return 0;
}

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


const long long INF = 1LL << 60;

int main() {
    int n, m, a[1010] = {},sum=0,count=0;
    cin >> n >> m;
    rep(i, n) {
        cin >> a[i];
        sum+=a[i];
    }

    rep(i, n)if ((double)a[i] >= (double)sum / (4.0 * m))count++;

    if (count >= m)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b) = listOfString()
    val num = (a + b).toDouble()
    val sqrt = Math.sqrt(num)

    println(if (sqrt == Math.floor(sqrt)) "Yes" else "No")
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 38000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main()
{
    ll n;cin>>n;
    vector<ll> a(n);
    //vector<ll> sum(n);
    map<ll,ll> sum;
    vector<ll> ans(n);
    vector<ll> tmp(n);
    vector<ll> tmp2(n);
    rep(i,n) {
        cin >> a[i];
        a[i]--;
        sum[a[i]]++;
    }
    ll ch = 0;
    rep(i, n)
    {
        tmp[i] = sum[i] * (sum[i] - 1) / 2;
        sum[i]--;
        tmp2[i] = sum[i] * (sum[i] - 1) / 2;
        sum[i]++;
        ch += tmp[i];
    }

    rep(i, n)
    {
        ll ok = 0;
        ok = ch - tmp[a[i]] + tmp2[a[i]];
        cout << ok << endl;
    }

    return 0;
}

Measured memory_bytes: 22528
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 998244353;

int main() {
    int N;
    cin >> N;
    vector<int> D(N), C(N);
    rep(i, N) cin >> D[i];

    if (D[0] != 0) {
        cout << "0" << endl;
        return 0;
    }
    if (count(D.begin(), D.end(), 0) > 1) {
        cout << "0" << endl;
        return 0;
    }

    sort(D.begin(), D.end());

    lint res = 1;
    C[0] = 1;

    for (int i = 1; i < N; i++) {
        if (D[i] - D[i-1] > 1) {
            cout << "0" << endl;
            return 0;
        }
        ++C[D[i]];
    }

    for (int i = 1; i <= D[N-1]; i++) {
        rep(j, C[i]) {
            res *= C[i-1];
            res %= MOD;
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
    int n, hbef, haft, ans = 1;
    cin >> n >> hbef;
    for(int i = 1; i < n; i++){
        scanf("%d", &haft);
        if(hbef < haft) haft--;
        if(hbef > haft) ans = 0;
        hbef = haft;
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void setIO(string name = "2019B") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(), "r", stdin);
    freopen((name+".out").c_str(), "w", stdout);
}

int main() {
    //setIO();
    double n; cin >> n;
    int num = ceil(n / 1.08) * 1.08;
    if (n == num) {
        cout << ceil(n / 1.08) << "\n";
    } else {
        cout << ":(" << "\n";
    }
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll p,q,m;cin>>p>>q>>m;
    ll a[p];f(i,0,p)cin>>a[i];
    ll b[q];f(i,0,q)cin>>b[i];
    ll mini=*min_element(a,a+p)+*min_element(b,b+q);
    while(m--){
        ll x,y,c;cin>>x>>y>>c;
        x--;y--;
        mini=min(mini,a[x]+b[y]-c);
    }
    cout<<mini;
    return 0;  
} 





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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

string acgt="ACGT";

bool judge(char c){
    REP(i, 0, 4){
        if(acgt[i]==c) return true;
    }
    return false;
}

int main(){
    int ans=0, tmp=0;
    string S;
    cin >> S;
    REP(i, 0, S.size()){
        if(judge(S[i])){
            tmp++;
        }else{
            ans = max(ans, tmp);
            tmp=0;
        }
    }
    ans = max(ans, tmp);
    P(ans);
    return 0;
}

Measured memory_bytes: 3640
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

h,w,k = map(int,readline().split())
x1,y1,x2,y2 = map(int,readline().split())

c = read().split()
inf = 10**7
cost = [[inf] * (w+2) for _ in range(h+2)]
for i in range(h):
    for j in range(w):
        if(c[i][j] == '@'):
            cost[i+1][j+1] = -1

for i in range(h+2):
    cost[i][0] = -1
    cost[i][-1] = -1

for j in range(w+2):
    cost[0][j] = -1
    cost[-1][j] = -1

cost[x1][y1] = 0
stack = [(x1,y1)]

cnt = 0
while(stack):
    cnt += 1
    next = set()
    while(stack):
        x,y = stack.pop()
        for dx,dy in zip([-1,1,0,0],[0,0,-1,1]):
            for j in range(1,k+1):
                jx = x + dx*j
                jy = y + dy*j
                if(cost[jx][jy] < cnt):
                    break
                next.add((jx,jy))

    for jx,jy in next:
        cost[jx][jy] = cnt
        stack.append((jx,jy))

if(cost[x2][y2]==inf):
    print(-1)
else:
    print(cost[x2][y2])

Measured memory_bytes: 129532
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n;
int a[200000];

int m;
int seg[600000];

void update(int i, int v) {
	i += m - 1;
	seg[i] = v;
	while (i > 0) {
		i = (i - 1) / 2;
		seg[i] = min(seg[i * 2 + 1], seg[i * 2 + 2]);
	}
}

int segq(int a, int b, int i, int l, int r) {
	if (r <= a || b <= l) return m;
	if (a <= l && r <= b) return seg[i];
	return min(segq(a, b, i * 2 + 1, l, (l + r) / 2), segq(a, b, i * 2 + 2, (l + r) / 2, r));
}

int segq(int a, int b) {
	return segq(a, b, 0, 0, m);
}

ll b[200002];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) cin >> a[i];

	m = 1;
	while (m < n) m *= 2;
	REP(i, 2 * m - 1) seg[i] = n + 1;
	REP(i, n) update(i, a[i]);

	ll res = 0;
	REP(i, n) {
		ll t = a[i];
		if (segq(0, i) >= a[i]) {
			t *= i + 1;
		}
		else {
			int l = 0, r = i;
			while (l + 1 < r) {
				int m = (l + r) / 2;
				if (segq(m, r) < a[i]) l = m;
				else r = m;
			}
			t *= i - l;
		}
		if (segq(i + 1, n) >= a[i]) {
			t *= n - i;
		}
		else {
			int l = i + 1, r = n;
			while (l + 1 < r) {
				int m = (l + r) / 2;
				if (segq(l, m) < a[i]) r = m;
				else l = m;
			}
			t *= l - i;
		}
		res += t;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3072
package main

import (
	"bufio"
	"fmt"
	"os"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner.Split(bufio.ScanWords)

	str := nextString()
	for i := len(str) - 1; i >= 0; i-- {
		fmt.Print(str[i:(i + 1)])
	}
	fmt.Print("\n")
}



Measured memory_bytes: 1068
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int flag = 1;
        if(s.charAt(0) != 'A'){
            flag = 0;
        }
        int countc = 0;
        for(int i = 2; i <= s.length()-2; i++){
            if(s.charAt(i) == 'C'){
                countc++;
            }
        }
        if(countc != 1){
            flag = 0;
        }
        if(s.charAt(1) <= 'Z' || s.charAt(s.length()-1) <= 'Z'){
            flag = 0;
        }
        if(flag == 1){
            System.out.print("AC");
        } else {
            System.out.print("WA");
        }
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int dp[1000][5][5][5];
//main
signed main(){
  int N,Q;cin>>N>>Q;
  string s;cin>>s;
  std::vector<int> v(1000000);
  v[0]=0;
  for(int i=1;i<N;i++){
    v[i+1]=v[i];
    if(s[i-1]=='A'&&s[i]=='C')v[i+1]++;
  }
  std::vector<int> l(Q),r(Q);
  for(int i=0;i<Q;i++)cin>>l[i]>>r[i];
  for(int i=0;i<Q;i++)cout<<v[r[i]]-v[l[i]]<<endl;
}


Measured memory_bytes: 10496
#include <iostream>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    
    int C0 = 0;
    int C1 = 0;
    int C2 = 0;
    int C3 = 0;
    
    for(int i = 0;i < N;i++) {
        string S;
        cin >> S;
        if(S == "AC") {
            C0++;
        }
        if(S == "WA") {
            C1++;
        }
        if(S == "TLE") {
            C2++;
        }
        if(S == "RE") {
            C3++;
        }
    }
    
    cout << "AC x " << C0 << endl;
    cout << "WA x " << C1 << endl;
    cout << "TLE x " << C2 << endl;
    cout << "RE x " << C3 << endl;
}

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



using namespace std;



using ll = long long;



int main(){

  string s;

  cin >> s;

  cin.ignore();



  if( s == "Sunny"){

    cout << "Cloudy" << endl;

    return 0;

  } else if(s == "Cloudy"){

    cout << "Rainy" << endl;

    return 0;

  } else {

    cout << "Sunny" << endl;

    return 0;

  }

  return 0;

}



Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<pii,int> ppiii ;
typedef unsigned long long ull ;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
int num[100]={0};

int main(){
	int N;
	cin>>N;
	vector<ll> a(N),b(N);
	for(int i=0;i<N;i++){
		cin>>a[i] >> b[i];
	}
	ll ans=(ll)0;
	ll check=0;
	for(int i=N-1;i>=0;i--){
		ll hoge=(a[i]+check)%b[i];
		if(hoge!=0){
			ans=ans+(b[i]-hoge);
			check=check+(b[i]-hoge);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1920
import sys
import collections

def m0():
    args = sys.stdin.read().split()
    s = args[0]
    cnt = list(s).count('1')
    print(cnt)

def m1():
    args = sys.stdin.read().split()
    s = args[0]
    counter = collections.Counter(list(s))
    print(counter['1'])

if __name__ == "__main__":
    m1()


Measured memory_bytes: 3316