akhauriyash/Code-Regression huggingface dataset:
//+-----------------+//
//|😜_Anonymous06_😜|//
//+-----------------+//
#include <bits/stdc++.h>
#define ll/*////////*/long long
#define gcd()/*////////*/___gcd()
#define pi/*////////*/3.141592653
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//------Enter your code here.------
	int n,ac=0,wa=0,tle=0,re=0;cin>>n;string a;for(int i=0;i<n;i++){cin>>a;if(a=="AC"){ac++;}else if(a=="WA"){wa++;}else if(a=="TLE"){tle++;}else if(a=="RE"){re++;}}
	cout<<"AC x "<<ac<<"\n";
	cout<<"WA x "<<wa<<"\n";
	cout<<"TLE x "<<tle<<"\n";
	cout<<"RE x "<<re<<"\n";
}

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

using namespace std;

using ll = long long;
using ld = long double;

struct line {
    ld k, b;
    ld calc(ld x) {
        return k * x + b;
    }

    // l.k != k
    ld intr(line l) {
        return (l.b - b) / (k - l.k);
    }

    ld intry(line l) {
        return calc(intr(l));
    }
};

vector<line> ls;

void add(line l) {
    while (ls.size() > 1 && ls.back().intr(ls[ls.size() - 2]) >= ls.back().intr(l)) ls.pop_back();
    ls.push_back(l);
}

ll calculate(ll x) {
    if (ls.size() == 1 || ls[0].intr(ls[1]) >= x) {
        return ls[0].calc(x);
    }
    int l = 1, r = ls.size();
    while (r - l > 1) {
        int m = (l + r) / 2;
        if (ls[m].intr(ls[m - 1]) <= x) {
            l = m;
        } else {
            r = m;
        }
    }
    return ls[l].calc(x);
}

void solve() {
    int n;
    ll c;
    cin >> n >> c;
    vector<ll> a(n);
    for (auto &e : a) cin >> e;

    vector<ll> dp(n, 1e18);
    dp[0] = 0;
    add({-2 * a[0], a[0] * a[0]});
    for (int i = 1; i < n; i++) {
        add({a[i] * -2, 2 * a[i] * a[i] + calculate(a[i]) + c});
    }
    cout << calculate(a[n - 1]) + a[n - 1] * a[n - 1] + c;
}

int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}


Measured memory_bytes: 13420
#include <iostream>
#include <string>
#include <array>

using namespace std;

int main(int argc, const char *argv[])
{
  string s;
  cin >> s;

  char ch1, ch2;
  int cnt1, cnt2;
  ch1 = ch2 = '\0';
  cnt1 = cnt2 = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == ch1) {
      cnt1++;
    } else if (s[i] == ch2) {
      cnt2++;
    } else if (ch1 == '\0') {
      ch1 = s[i];
    } else if (ch2 == '\0') {
      ch2 = s[i];
    } else {
      cout << "No\n";
      return 0;
    }
  }

  if (cnt1 == cnt2) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  
  
  return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    import sys
    from collections import deque

    H, W = map(int, sys.stdin.readline().split())
    grid = []
    for _ in range(H):
        grid.append(list(sys.stdin.readline().rstrip()))

    # 白いマスを数える
    ans = 0
    for h in range(H):
        for w in range(W):
            ans += 1 if grid[h][w]=="." else 0

    # BFSで最短路を求める
    dist = [[float("inf") for _ in range(W)] for __ in range(H)]
    dist[0][0] = 1
    que = deque([(0,0)])
    while que:
        h, w = que.popleft()
        if grid[h][w] == "x": continue
        grid[h][w] = "x"

        for nh, nw in ((h-1,w), (h+1,w), (h,w-1), (h,w+1)):
            if nh==-1 or nh==H or nw==-1 or nw==W: continue
            if grid[nh][nw] != ".": continue
            dist[nh][nw] = dist[h][w] + 1
            que.append((nh, nw))

    if dist[H-1][W-1] == float("inf"):
        print(-1)
    else:
        print(ans - dist[H-1][W-1])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3436
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>


using namespace std;

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

#define fs first
#define sc second

vector<P> x;

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

    for(int i = 0; i < N; i++){
        ll a, b;
        cin >> a >> b;
        x.emplace_back(P(b, a));
    }

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

    ll s = 0;
    bool res = true;
    for(auto y: x){
        ll a = y.sc;
        ll b = y.fs;
        s += a;
        if(s > b){
            res = false;
        }
    }

    if(res){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }




    return 0;
}


Measured memory_bytes: 6576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,k;cin>>n>>k;
  V<db> v(n);
  rep(i,0,n)cin>>v[i];
  rep(i,0,n)v[i]=(v[i]+1.0)/2.0;

  db sum=0,ans;
  rep(i,0,k){
    sum+=v[i];
  }

  ans=sum;
  rep(i,k,n){
    sum-=v[i-k];
    sum+=v[i];
    chmax(ans,sum);
    cerr<<sum<<ENDL;
  }
  cout<<ans<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

def check_digit(n):
    cnt = 0
    while n > 0:
        n //= 10
        cnt += 1
    return cnt

ans = 10**9 + 7
for i in range(1, int(N**0.5//1)+1):
    if N % i == 0:
        a = i
        b = N // i
        ans = min(ans, max(check_digit(a), check_digit(b)))

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 1e3+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const int MOD = 1e9+7;

map<int, vector<int> > S, T;
int d;
int n,q;
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
	{
		int s,t,x;
		scanf("%d%d%d",&s,&t,&x);
		S[s-x].push_back(x);
		T[t-x].push_back(x);
	}
	
	auto Sit = S.begin();
	auto Tit = T.begin();
	multiset<int> H;
	for (int i=1;i<=q;++i)
	{
		int d;
		scanf("%d",&d);
		while (Sit != S.end() && Sit->first <= d)
		{
			for (auto x : Sit->second)
				H.insert(x);
			Sit ++;
		}
		while (Tit != T.end() && Tit->first <= d)
		{
			for (auto x : Tit->second)
				H.erase(H.lower_bound(x));
			Tit ++;
		}
		int ans = 0;
		if(H.empty())
		{
			ans = -1;
		}
		else
			ans = *H.begin();
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 54400
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,h1,h2,k1,k2;
    cin >>h1>>h2>>k1>>k2>>a>>b>>c>>d;
    h1=h1*a+(h1/10)*c;
    h2=h2*b+(h2/20)*d;
    k1=k1*a+(k1/10)*c;
    k2=k2*b+(k2/20)*d;
    if((h1+h2)==(k1+k2))cout << "even" <<endl;
    else if(h1+h2>k1+k2)cout << "hiroshi" <<endl;
    else cout << "kenjiro" <<endl;
 }


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll n,m,q,a[50],b[50],c[50],d[50];
ll ans=0;
void dfs(ll x){
    ll y=x,z=0,p=x;
    vec s;
    rep(i,n) s.push_back(p%10),p/=10;
    reverse(all(s));
    rep(i,q){
        if((s[b[i]-1])-(s[a[i]-1])==c[i]) z+=d[i];
    }
    ans=max(ans,z);
    if(x<pow(10,n-1))for(int i=s[n-1]+(s[n-1]==0);i<=m-1;i++) dfs(x*10+i);
}
int main(){
    cin>>n>>m>>q;
    rep(i,q) cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(0);
    cout<<ans;
}

Measured memory_bytes: 4000
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

l = []
if A%10 > 0:
  l.append(A%10)
if B%10 > 0:
  l.append(B%10)
if C%10 > 0:
  l.append(C%10)
if D%10 > 0:
  l.append(D%10)
if E%10 > 0:
  l.append(E%10)
  
ans = len(l)*10 + A + B + C + D + E - sum(l)
if len(l) > 0:
  ans += min(l) - 10
print(ans)

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

using namespace std;

#define fastio cin.tie(NULL);cout.tie(NULL);ios_base::sync_with_stdio(0);
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MAXN 200005
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define int long long
#define endl '\n'

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <vi> matriz;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// auto timer_start = chrono::steady_clock::now().time_since_epoch().count();

struct line {
    ll a, b;
    ll get(ll x){
        return a * x + b;
    }
};

struct node {
    ll i, j;
    line res;
    node * l, * r;
    node(ll i, ll j, line res) : l(NULL), r(NULL), i(i), j(j), res(res){ }
} * seg;

void update(node * &seg, line v){
    ll i = seg->i, j = seg->j;
    ll mid = i + (j - i) / 2;
    bool checkL = seg->res.get(i) > v.get(i);
    bool checkM = seg->res.get(mid) > v.get(mid);

    if(checkM) swap(seg->res, v);
    if(i == j) return;

    if(checkL != checkM){
        if(!seg->l) seg->l = new node(i, mid, v);
        else update(seg->l, v);
    } else {
        if(!seg->r) seg->r = new node(mid + 1, j, v);
        else update(seg->r, v);
    }
}

ll query(node * seg, ll x){
    ll i = seg->i, j = seg->j;
    ll mid = i + (j - i) / 2;
    ll v = seg->res.get(x);

    if(i == j) return v;
    if(x <= mid){
        if(seg->l) return min(v, query(seg->l, x));
    } else if(seg->r){
        return min(v, query(seg->r, x));
    }
    return v;
}


int n, c;

int32_t main(){
    fastio
    cin >> n >> c;
    int aux, res = INF;
    for(int i = 1; i <= n; i++){
        cin >> aux;
        if(i == 1){
            seg = new node(0, 1e9, {-2 * aux, aux * aux});
        } else {
            res = c + aux * aux + query(seg, aux);
            update(seg, {-2 * aux, res + aux * aux});
        }
    }
    cout << res << endl;

    return 0;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	
	int ans = 0;

	for (int i = 0; i < 1000; i++) {
		int tmp_flg = 0;
		for (int j = 0; j < N; j++) {
			if (tmp_flg == 0 && S[j] - '0' == i / 100) {
				++tmp_flg;
				continue;
			}
			else if (tmp_flg == 1 && S[j] - '0' == (i / 10) % 10) {
				++tmp_flg;
				continue;
			}
			else if (tmp_flg == 2 && S[j] - '0' == i % 10) {
				++tmp_flg;
				break;
			}
		}
		if (tmp_flg == 3) {
			ans++;
		}
	}

	cout << ans;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll int r;
    cin>>r;
    long double c=3.141592653589793238;
    long double cc=2*c*r;
    cout<<fixed<<setprecision(12)<<cc;

    return 0;
}

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

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let k: usize = read!();

    println!("{}", if (n+1) / 2 >= k { "YES" } else { "NO" });
}


Measured memory_bytes: 2076
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int x=0,f=1;
	while(c<'0'||c>'9'){ if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
int n,a[200005],b[200005],le[200005],ri[200005],vis[200005];
long long ans;
int main(){
	n=read();
	for(int i=1;i<=n;++i) a[i]=read(),b[a[i]]=i;
	for(int i=n;i>=1;--i){
		int pos=b[i];vis[pos]=1;le[pos]=ri[pos]=1;
		if(vis[pos-1]) le[pos]+=le[pos-1];
		if(vis[pos+1]) ri[pos]+=ri[pos+1];
		if(vis[pos-1]) ri[pos-le[pos-1]]+=ri[pos];
		if(vis[pos+1]) le[pos+ri[pos+1]]+=le[pos];
		ans+=(1ll*le[pos]*ri[pos]*i);
	//	cout<<i<<' '<<le[pos]<<' '<<ri[pos]<<' '<<(1ll*le[pos]*ri[pos]*i)<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4096
n = int(input())

st= set()
back=""
flg=True
for i in range(n):
    s=input()

    if i>0 and back!=s[0]:
        flg=False
    
    back=s[-1]
    st.add(s)

if flg and len(st)==n:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int pos = 0;
long stack[1000];

void push(long c) {
    stack[pos] = c;
    pos++;
}

long pop() {
    pos--;
    return stack[pos];
}

int main() {

    char chars[100];
    while (scanf("%s", chars) != EOF) {
        if (chars[0] == '+') {
            long b = pop();
            long a = pop();
            push(a + b);
        } else if (chars[0] == '-') {
            long b = pop();
            long a = pop();
            push(a - b);
        } else if (chars[0] == '*') {
            long b = pop();
            long a = pop();
            push(a * b);
        } else {
            push(atol(chars));
        }
    }

    printf("%ld\n", pop());

    return 0;
}



Measured memory_bytes: 3200
#include <iostream>

using namespace std;




int main(){
    int int1, int2, int3, n;
    cin >> int1 >> int2 >> int3;
    if((int2 + int3) >  int1){
        cout << (int2 + int3) - int1 << endl;
    } else{
        n  = 0;
        cout <<  n << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	char c; cin>>c;
	cout<<char(c+1)<<'\n';
	
	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(lambda x: int(x), input().split()))

A = [a - 1 for a in A]

now = 0
while K:
    if K % 2: now = A[now]
    A = [A[a] for a in A]
    K //= 2

print(now + 1)

Measured memory_bytes: 169824
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#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;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


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

  if (abs(a - c) <= d) {
    cout << "Yes" << endl;
  } else if (abs(a - b) <= d && abs(b - c) <= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

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

int main()
{
    int inp[5];
    for (int i = 0; i < 5; i++)
        scanf("%d", &inp[i]);
    sort(inp, inp + 5);

    int mn = INT_MAX, sum = 0;
    // 29 20 7 35 120
    do {
        sum = 0;
        for (int i = 0; i < 5; i++) {
            sum += inp[i];
            if (i < 4 && sum % 10 > 0)
                sum += 10 - sum % 10;

            // printf("sum %d\n", sum);
        }
        mn = min(mn, sum);
    } while (next_permutation(inp, inp + 5));

    printf("%d\n", mn);

    return 0;
}


Measured memory_bytes: 256
import numpy as np

n, k = [int(x) for x in input().split()]
s = input()

zero_list = np.array([len(x) for x in s.split("1") if len(x) > 0])
one_list = np.array([len(x) for x in s.split("0") if len(x) > 0])

if k >= len(zero_list):
    print(len(s))
else:
    max_num = 0

    if len(zero_list) < len(one_list):
        for i in range(len(zero_list) - k + 1):
            tmp = zero_list[i:i+k].sum() + one_list[i:i+k+1].sum()
            if tmp > max_num:
                max_num = tmp
    else:
        if len(zero_list) == len(one_list) and int(s[0]) == 1:
            zero_list = np.insert(zero_list, 0, 0)
        max_num = zero_list[:k].sum() + one_list[:k].sum()
        for i in range(len(one_list) - k):
            tmp = zero_list[i+1:i+k+1].sum() + one_list[i:i+k+1].sum()
            if tmp > max_num:
                max_num = tmp
        tmp = zero_list[-k:].sum() + one_list[-k:].sum()
        if tmp > max_num:
            max_num = tmp

    print(max_num)

Measured memory_bytes: 15860
#include <iostream>
#include <string>
#include <sstream>

int main()
{
	while (true)
	{
		std::string text;
		std::getline(std::cin, text, '\n');

		if (text == "0")
			break;

		long long sum = 0;
		for (int i = 0; i < text.size(); ++i)
		{
			sum += std::stoll(text.substr(i, 1));
		}

		std::cout << sum << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3144
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

dp = [[0,0,0] for _ in range(n)]
dp[0][0], dp[0][1], dp[0][2] = l[0][0], l[0][1], l[0][2]

for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][k] = max(dp[i][k], dp[i-1][j] + l[i][k])

print(max(dp[-1]))

Measured memory_bytes: 47372
n = int(input())
a = list(map(int,input().split()))
pos = []
neg = []
cnt = 0
for i in a:
    if i > 0:
        pos.append(i)
    elif i < 0:
        neg.append(i)
    else:
        cnt += 1
if cnt != 0 or len(neg) % 2 == 0:
    print(sum(pos) - sum(neg))
else:
    pos = sorted(pos)
    neg = sorted(neg)
    if pos == []:
      print(-sum(neg[:-1])+neg[-1])
      exit()
    else:
      b = min(pos)
    c = -max(neg)
    pos = pos[1:]
    neg = neg[:-1]
    r = sum(pos) - sum(neg)
    m = max(b - c, c - b)
    print(r + m)


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

public class Main {
	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int answer = 0;
			int input = sc.nextInt();
			boolean[] primelist = new boolean[input+1];
			Arrays.fill(primelist, true);
			primelist[0] = false;
			primelist[1] = false;

			for(int i = 2; i <= input;i++){
				if(primelist[i]){
					for(int j = i + i; j <= input; j+=i){
						primelist[j] = false;			
					}
					++answer;
				}
			}	
			System.out.println(answer);
		}
	}
	public static void main(String[] args) {
		new Main().run();

	}
}

Measured memory_bytes: 35660
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
const int maxn = 2e5 + 5;
vector<pair<int,pair<int,int>>>g[55];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll dp[55][2555];
    pair<ll,ll>ch[55];
    int n, m, s;
    cin >> n >> m >> s;
    f(m) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        g[a].pb({b,{c,d}});
        g[b].pb({a,{c,d}});
    }
    f1(n) {
        cin >> ch[i].F >> ch[i].S;
    }
    memset(dp,0x3f,sizeof(dp));
    priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>>pq;
    if (s > 2500) {
        dp[1][2500] = 0;
        pq.push({0,{1,2500}});
    }
    else {
        dp[1][s] = 0;
        pq.push({0,{1,s}});
    }
    while (pq.size()) {
        auto now = pq.top();
        pq.pop();
        if (now.F > dp[now.S.F][now.S.S])continue;
        while (1) {
            for (auto i:g[now.S.F]) {
                if (now.S.S >= i.S.F) {
                    int nm = now.S.S - i.S.F;
                    ll nc = now.F + i.S.S;
                    if (dp[i.F][nm] > nc) {
                        dp[i.F][nm] = nc;
                        pq.push({nc,{i.F,nm}});
                    }
                }
            }
            if (now.S.S == 2500)break;
            //cout << now.S.S<<endl;
            now.S.S += ch[now.S.F].F;
            now.F += ch[now.S.F].S;
            now.S.S = min(now.S.S,2500);
            if (dp[now.S.F][now.S.S] > now.F) {
                dp[now.S.F][now.S.S] = now.F;
            }
        }
    }
    for (int i = 2 ; i <= n ; i++) {
        ll mi = 1e18;
        fr(j,0,2501) {
            mi = min(mi,dp[i][j]);
        }
        cout << mi << '\n';
    }
}


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

int D;
int C[26];
int S[365][26];
int ans[365];
int final_S;

bitset<365> has_contest[26];
void set_contest(int day, int type) { has_contest[type].set(364 - day); }
void reset_contest(int day, int type) { has_contest[type].reset(364 - day); }
void test_contest(int day, int type) { has_contest[type].test(364 - day); }
// -1 if not found
int last_contest(int type) {
    int t = has_contest[type]._Find_first();
    return 364 - t;
}

void init_ans() {
    for (int i = 0; i < D; i++) {
        vector<pair<int, int>> gain;
        for (int j = 0; j < 26; j++) {
            int d = i - last_contest(j);
            gain.emplace_back(S[i][j] - C[j] * d, j);
        }
        sort(gain.rbegin(), gain.rend());
        int type = gain.front().second;
        final_S += gain.front().first;
        set_contest(i, type);
        ans[i] = type;
    }
}

void print_ans() {
    for (int i = 0; i < D; i++) {
        cout << ans[i] + 1 << '\n';
    }
    cerr << "final S: " << final_S << endl;
}

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

    cin >> D;
    for (int i = 0; i < 26; i++) cin >> C[i];
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> S[i][j];
        }
    }

    init_ans();
    print_ans();
}


Measured memory_bytes: 3708
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <algorithm>

using namespace std;

struct zahyou{
	int x;
	int y;
};

typedef struct zahyou Z;

Z a[200];

int main()
{
	int N;
	while(1){
		cin >> N;
		if(N == 0) break;
		a[0].x = 1;
		a[0].y = 1;
		int max_x=1, min_x=0, max_y=1, min_y=0, n, d;
		for(int i = 1; i < N; i++){
			 cin >> n >> d;
			 a[i].x = a[n].x;
			 a[i].y = a[n].y;
			 if(d == 0){
			 	a[i].x--;
				min_x = min(a[i].x-1, min_x); 
			 } else if(d == 1){
			 	a[i].y--;
			 	min_y = min(a[i].y-1, min_y);
			 } else if(d == 2){
			 	a[i].x++;
			 	max_x = max(a[i].x, max_x);
			 } else if(d == 3){
			 	a[i].y++;
			 	max_y = max(a[i].y, max_y);
			 }
		}
		int w, h;
		w = max_x - min_x;
		h = max_y - min_y;
		cout << w << ' ' << h << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import heapq
from collections import defaultdict

N,m,s,t=map(int,input().split())

V=defaultdict(set)
V2=defaultdict(set)
for i in range(m):
  a,b,c,d=map(int,input().split())
  V[a-1].add((b-1,c))
  V[b-1].add((a-1,c))
  V2[a-1].add((b-1,d))
  V2[b-1].add((a-1,d))

def dijkstra(n,v,dedic):
  d=[float('inf')]*n
  d[v]=0
  
  hq=[(0,v)]
  
  while hq:
    u = heapq.heappop(hq)[1]
    for nv,c in dedic[u]:
      if d[nv]>d[u]+c:
        d[nv]=d[u]+c
        heapq.heappush(hq,(d[u]+c,nv))
        
  return d

ans=dijkstra(N,s-1,V)
ans2=dijkstra(N,t-1,V2)
ans3=[10**15 for i in range(N)]
ans3[N-1]=ans[N-1]+ans2[N-1]
for i in range(N-2,-1,-1):
  ans3[i]=min(ans3[i],ans3[i+1],ans[i]+ans2[i])

for i in range(N):
  print(10**15-ans3[i])

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

const double PI = acos(-1.0);
struct Point{
	double x,y;
};

void koch(int n, Point a, Point b) {
	// ????????????
	if (n == 0)
		return;
	// ????????????s,t ???(u ??? s,t ????????????)
	Point s, t, u;
	// ?§????????????¬?????§???
	double th = PI * 60.0 / 180.0;
	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;


	koch(n - 1, a, s);
	printf("%.8lf %.8lf\n", s.x, s.y);
	koch(n - 1, s, u);
	printf("%.8lf %.8lf\n", u.x, u.y);
	koch(n - 1, u, t);
	printf("%.8lf %.8lf\n", t.x, t.y);
	koch(n - 1, t, b);
}
int main(){
	Point a, b;
	int n;
	scanf("%d", &n);

	// ????§????
	a.x = a.y = 0;
	b.x = 100, b.y = 0;
	printf("%.8lf %.8lf\n", a.x, a.y);
	koch(n, a, b);
	printf("%.8lf %.8lf\n", b.x, b.y);
	return 0;
}

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

int main() {
    priority_queue<char, vector<char>, greater<char> > que_s;
    priority_queue<char> que_t;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.length(); i++) {
        que_s.push(s[i]);
    }
    for (int i = 0; i < t.length(); i++) {
        que_t.push(t[i]);
    }
    while(!que_s.empty()) {
        if (que_t.empty()) {
            printf("No\n");
            return 0;
        }
        if (que_s.top() > que_t.top()) {
            printf("No\n");
            return 0;
        }else if (que_s.top() < que_t.top()) {
            printf("Yes\n");
            return 0;
        }
        que_s.pop(); que_t.pop();
		if (que_s.empty() && que_t.empty()) {
			printf("No\n");
			return 0;
		}
    }
    printf("Yes\n");
    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 ll long long

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n-1);
	int happy = 0;
	rep(i, n) cin >> a.at(i);
	rep(i, n){
		cin >> b.at(i);
		happy += b.at(i);
	}
	rep(i, n-1) cin >> c.at(i);

	rep(i, n-1){
		if(a.at(i)+1 == a.at(i+1)) happy += c.at(a.at(i)-1);
	}

	cout << happy << endl;
	return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
list_size = 2000001

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size-1):
	f_list[i+1] = (f_list[i] * (i+1)) % MOD

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(list_size-2, -1, -1):
	f_r_list[i] = (f_r_list[i+1] * (i+1)) % MOD

def comb(n, r):
	if n < r or r < 0:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (f_list[n] * f_r_list[n-r] * f_r_list[r]) % MOD 

k = int(input())
s = input()
n = len(s)
ps = [1]
for i in range(k+1):
	ps.append((ps[-1] * 25) % MOD)
ans = 0
for i in range(k+1):
	ans += comb(n+k, i) * ps[i]
	ans %= MOD
print(ans)

Measured memory_bytes: 214692
N, K = map(int,input().split())
l = []
l1 = []
if K%2==1:
  for i in range(1, N+1):
    if i%K==0:
      l.append(i)
  print(len(l)**3)
else:
  for i in range(1, N+1):
    if i%K==0:
      l1.append(i)
    elif i%K==K//2:
      l.append(i)
  print(len(l)**3+len(l1)**3)

Measured memory_bytes: 11016
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<array>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		vector<string> strs(n);
		rep(i,n){
			cin >> strs[i];
		}
		rep(i,n) rep(j,strs[i].size()){
			if(strs[i][j]!='.'){
				if(j>0) strs[i][j-1]='+';
				break;
			}
		}

		rep(i,n) rep(j,strs[i].size()){
			if(strs[i][j]=='+'){
				for(int k=i-1;k>0;k--){
					if(strs[k][j] !='.')break;
					strs[k][j]='|';
				}
			}
		}

		rep(i,n) rep(j,strs[i].size()){
			if(strs[i][j]=='.') strs[i][j] =' ';
		}

		rep(i,n){
			cout << strs[i] << endl;
		}
	}



	return 0;
}

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


int main(){
  int n,r;
  cin>>n>>r;
  int ans;
  
  if(n>=10)ans=r;
  else ans=r+100*(10-n);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N=int(input())
p=[]
q=dict()
for i in range(2,N+1):
    for j in p:
        if i%j==0:
            break
    else:
        p.append(i)
for i in p:
    q[i]=0
for i in range(1,N+1):
    for j in p:
        for k in range(6,0,-1):
            if i%(j**k)==0:
                q[j]+=k
                break
r=list(q.values())
cnt_74,cnt_24,cnt_14,cnt_4,cnt_2=0,0,0,0,0
for i in r:
    if i>=74:
        cnt_74+=1
    if i>=24:
        cnt_24+=1
    if i>=14:
        cnt_14+=1
    if i>=4:
        cnt_4+=1
    if i>=2:
        cnt_2+=1
print(cnt_74+cnt_24*(cnt_2-1)+cnt_14*(cnt_4-1)+cnt_4*(cnt_4-1)*(cnt_2-2)//2)

Measured memory_bytes: 3064
import itertools 

H, W, K = map(int, input().split())
C = []
HS = []
WS = []
T = 0

def f(x):
  if x == "#":
    return 1
  else:
    return 0

for i in range(H):
  X = list(input())
  c = [f(x) for x in X]
  C.append(c)
  HS.append(sum(c))
  T += sum(c)

for j in range(W):
  cnt = 0
  for i in range(H):
    cnt += C[i][j]
  WS.append(cnt)
  
ans = 0

for h in itertools.product([0, 1], repeat = H):
  for w in itertools.product([0, 1], repeat = W):
    cnt = 0
    for i in range(H):
      if h[i] == 1:
        cnt += HS[i]
    for j in range(W):
      if w[j] == 1:
        cnt += WS[j]
    for i in range(H):
      for j in range(W):
        if h[i] == 1 and w[j] == 1:
          cnt -= C[i][j]
    if T - cnt == K:
      ans += 1

print(ans)

Measured memory_bytes: 9280
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=1; i<=n; i++){
    scanf("%hu",&A[i]);
  }

  for(i=0; i<=VMAX; i++){
    C[i] = 0;
  }

  for(j=1; j<=n; j++){
    C[A[j]]++;
  }

  for(i=1; i<=VMAX; i++){
    C[i] = C[i] + C[i-1];
  }

  for(j=n; j>=1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1; i<=n; i++){
    printf("%d",B[i]);
    if(i<n){
      printf(" ");
    }
  }

  printf("\n");



  return 0;
}



Measured memory_bytes: 9596
N=int(input())
list=list(map(int,input().split()))
while len(list) != 0and max(list) > len(list):
    list = [i for i in list if i < len(list)]
#list2 = [i for i in list if i < N]
set = set(list)
cnt=0
for i in set:
    c=list.count(i)
    if c > i:
        cnt +=c-i
    elif c < i:
        cnt +=c
print(N-len(list)+cnt)

##できなかった．


Measured memory_bytes: 14268
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << "  " << y << endl
#define dbg3(x, y, z) cout << x << "  " << y << "  " << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    bool flag = 0;
    if(n >= 700 and n <= 799){
        flag = true;
    }
    n %= 100;
    if(n >= 70 and n <= 79){
        flag = true;
    }
    n %= 10;
    if(n == 7){
        flag = true;
    }
    if( flag){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){

	double l,a,x;
	while(cin>>a>>l>>x){
	double M=(a*sqrt(l*l-(a/2)*(a/2)))/2;
	double S=(l*sqrt(((l+x)/2)*((l+x)/2)-(l/2)*(l/2)))/2;
	printf("%.6f\n",M+2*S);

	}
	return 0;
}

Measured memory_bytes: 1228
import sys
readline = sys.stdin.readline

S = readline().rstrip()

from collections import deque
S = deque(S)

Q = int(readline())
turn = False
for i in range(Q):
  query = readline().split()
  if query[0] == "1":
    turn ^= True
  elif query[0] == "2":
    if query[1] == "1":
      if turn:
        S.append(query[2])
      else:
        S.appendleft(query[2])
    elif query[1] == "2":
      if turn:
        S.appendleft(query[2])
      else:
        S.append(query[2])

S = "".join(S)
if turn:
  S = S[::-1]
  
print(S)

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

int main() {
  int N,K;cin>>N>>K;
  if(N%K == 0) cout << 0 << endl;
  else cout << 1 << endl;
}


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

using namespace std;

bool vis[200009];
int main()
{
   long long  n, k;
   cin >> n >> k;
   
   vector<long long> a(n+1);
   for(int i = 0; i < n; i++) {
       cin >> a[i];
       a[i]--;
   }
   
   vector<long long> path;
   vector<long long> pos(n+1);
   int i = 0;
   while(1) {
       
       if(vis[i] == true) break;
       pos[i] = path.size();
       path.push_back(i);
       vis[i] = true; 
       i = a[i];
   }
   
   long long cyclestart = pos[i];
   long long cyclelen = (int)path.size()-cyclestart;
   
   if(k <= path.size()-1) {
       cout << path[k]+1 << endl;
       return 0;
   }
   
   else {
       
       k -=  cyclestart;
       k %= cyclelen;
       cout << path[cyclestart+k]+1 << endl;
   }
   return 0;
}

Measured memory_bytes: 8688
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

using namespace std;

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


int main(){
	int W;
	int idx=1;
	while(~scanf("%d",&W)){
		if(W==0) break;
		int N;
		vector<P> bag;

		cin >> N;

		int** dp = new int*[N+1];
		for(int i=0;i<N+1;i++){
			dp[i] = new int[1000]();
		}



		for(int i=0;i<N;i++){
			int v,w;
			scanf("%d,%d",&v,&w);
			bag.push_back(P(v,w));
		}

		for(int i=0;i<bag.size();i++){
			for(int j=0;j<=W;j++){
				if(j < bag[i].second){
					dp[i+1][j] = dp[i][j];
				}
				else{
					dp[i+1][j] = max(dp[i][j], dp[i][j-bag[i].second] + bag[i].first);
				}
			}
		}


		int max_v=-1;
		int max_w=-1;
		for(int j=0;j<=W;j++){
			if(max_v < dp[N][j]){

				max_v = dp[N][j];
				max_w = j;
			}
		}

		printf("Case %d:\n%d\n%d\n",idx++,max_v,max_w);
	}


}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

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

int main(){
	int a, b, k; scanf("%d%d%d", &a, &b, &k);
	int g = gcd(a, b);
	// DEBUG("%d\n", g);
	for(int i=g; i>=1; i--){
		if(g%i) continue;
		k--;
		// DEBUG("%d\n", i);
		if(!k){
			printf("%d\n", i);
			return 0;
		}
	}
}


Measured memory_bytes: 256
len = gets.to_i
arr = gets.split(' ').map(&:to_i)
cnt = 0

0.upto(len-2) do |i|
  (len-1).downto(i+1) do |j|
    if arr[j] < arr[j-1]
      arr[j], arr[j-1] = arr[j-1], arr[j]
      cnt += 1
    end
  end
end

puts arr.join(' ')
puts cnt


Measured memory_bytes: 6864
using System;
using System.Collections;
using System.Linq;
class Program
{
    public static int Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        int d, x;
        d = int.Parse(s[0]);
        x = int.Parse(s[1]);
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = int.Parse(Console.ReadLine());

        int ans = x;
        for (int i = 0; i < n; i++)
            ans += 1 + (d - 1) / a[i];

        Console.WriteLine(ans);


        return 0;
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 110;
int a[mxn];

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

	int n; cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];

	int cnt = 0;
	for(int i=1; i<=n; i++) if(a[i]&1 and i&1) cnt++;

	cout << cnt << '\n';



	return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int MAX_N = 100;
  int time[MAX_N];
  int n;
  cin >> n;
  int sm = 0;
  REP(i,n){
      cin >> time[i];
      sm += time[i];
  }
  int m;
  int p, x;
  cin >> m;
  REP(i,m){
      cin >> p >> x;
      cout << sm - time[p-1] + x << endl;
  }

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    sc.close();
    System.out.println(isStrongPalindrome(s) ? "Yes" : "No");
  }
  static boolean isStrongPalindrome(String s){
    int left1 = 0;
    int right1 = s.length() - 1;
    int left2 = 0;
    int right2 = ((s.length() - 1 ) / 2) - 1;
    while(left1 <= right1){
      if(s.charAt(left1) != s.charAt(right1)){
        return false;
      }
      left1++;
      right1--;
    }
    while(left2 <= right1){
      if(s.charAt(left2) != s.charAt(right2)){
        return false;
      }
      left2++;
      right2--;
    }
    return true;
  }
}


Measured memory_bytes: 35600
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef pair<long,long> pr;
typedef vector<pr> VP;
typedef vector<VP> VVP;

VI used;
VI dis;
VVP edge;
void dfs(long node){
    if (used[node]) return;
    used[node] = 1;

    REP(j,(long)edge[node].size()) {
        long next_node = edge[node][j].first;
        if (used[next_node]) {
            if (dis[next_node] != dis[node] + edge[node][j].second) {
                cout << "No" << endl;
                exit(0);
            }
        }
        else {
            dis[next_node] = dis[node] + edge[node][j].second;
            dfs(next_node);
        }
    }
}


int main(void) {
    long N,M;
    long  l,r,d;
    cin >> N >> M;
    edge = VVP(N+1,VP(0));
    dis = VI(N+1,0);
    used = VI(N+1,0);
    REP(i,M){
        cin >> l >> r >> d;
        edge[l].push_back(make_pair(r,d));
        edge[r].push_back(make_pair(l,-(d)));
    }

    FOR(i,1,N+1) {
        if (! used[i]) dfs(i); // スタートするノードの距離を0として始める。
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 16384
s = ''
while True:
    try:
        s += input().lower()
    except EOFError:
        break
alpha = 'abcdefghijklmnopqrstuvwxyz'
c = {}
for _ in alpha:
    c[_] = 0
for ch in s:
    
    if ch.isalpha():
        c[ch] += 1
        
for key in c:
    print(key,':', c[key])


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

int main() {
    int64_t a, b, k;
    cin >> a >> b >> k;
    if (a-k >= 0) {
        cout << a-k << " " << b << endl;
    } else if (a + b - k >= 0) {
        cout << 0 << " " << a + b - k << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
long long gcd(long long a,long long b)
{
	long long n=a%b;
	while(n!=0)
	{
		a=b;
		b=n;
		n=a%b;
	}
	return b;
}
long long i,n,m;
long long ans=1;
int main(void)
{
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&m);
		ans=ans/gcd(ans,m)*m;
	}
	printf("%lld\n",ans);
}
//看看对不对

Measured memory_bytes: 128
#include <string>
#include <iostream>
#define rng(x, y) (0 <= x && x < W && 0 <= y && y < H)
using namespace std;
int T, H, W, N; string s[22], t;
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
int main() {
	cin >> T;
	while (T--) {
		cin >> H >> W;
		for (int i = 0; i < H; i++) cin >> s[i];
		cin >> N >> t;
		int tx = 0, ty = 0, d = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				char c = s[i][j];
				if (c == 'v') tx = j, ty = i, d = 0;
				if (c == '>') tx = j, ty = i, d = 1;
				if (c == '^') tx = j, ty = i, d = 2;
				if (c == '<') tx = j, ty = i, d = 3;
			}
		}
		for (int i = 0; i < N; i++) {
			char c = t[i];
			if (c == 'D') d = 0, s[ty][tx] = 'v';
			if (c == 'R') d = 1, s[ty][tx] = '>';
			if (c == 'U') d = 2, s[ty][tx] = '^';
			if (c == 'L') d = 3, s[ty][tx] = '<';
			if (c != 'S') {
				int sx = tx + dx[d], sy = ty + dy[d];
				if (rng(sx, sy) && s[sy][sx] == '.') s[sy][sx] = s[ty][tx], s[ty][tx] = '.', tx = sx, ty = sy;
			}
			else {
				int sx = tx, sy = ty;
				while (true) {
					sx += dx[d];
					sy += dy[d];
					if (!rng(sx, sy)) break;
					if (s[sy][sx] == '*') { s[sy][sx] = '.'; break; }
					if (s[sy][sx] == '#') break;
				}
			}
		}
		for (int i = 0; i < H; i++) cout << s[i] << endl;
		if (T) cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, long long K){
  ll x = ((N / K)+1)*K;
  if(N % K == 0)
    std::cout << 0 << std::endl;
  else
    std::cout << min(N, abs(N-x)) << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  solve(N, K);
  return 0;
}



Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;

int main()
{
    ll A, P;
    cin >> A >> P;
    ll tmp = A*3 + P;
    print(tmp / 2);
    return 0;
}

Measured memory_bytes: 256
N,Y = map(int,input().split())

for i in range(N+1):
    for j in range(N+1):
        k = N-i-j
        if 1000*i+j*5000+k*10000 == Y and i+j+k == N and k >= 0:
            print(k,j,i)
            exit()
else:
    print(-1,-1,-1)

Measured memory_bytes: 9140