akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	int ans = 0;
	rep(i, m) {
		Union_Find uni(n);
		rep(j, m) {
			if (i != j) {
				uni.unite(a[j], b[j]);
			}
		}
		if (!uni.same(a[i], b[i])) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

w,h = inm()
p = []
q = []
for i in range(w):
    p.append(inn())
for i in range(h):
    q.append(inn())
x = w+1
y = h+1
p.sort(reverse=True)
q.sort(reverse=True)
ans = 0
while x>1 or y>1:
    #ddprint(f"{x=} {y=} {p} {q}")
    if x>1 and (y==1 or p[-1]<=q[-1]):
        ans += p[-1]*y
        p.pop()
        x -= 1
    else:
        ans += q[-1]*x
        q.pop()
        y -= 1
print(ans)


Measured memory_bytes: 88352
/*
ID: Aman Raj
LANG: C++
TASK: preface
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

	   //vector<ll > vten(7),vfive(7),vfifty(7),vhundred(7),vfivehundred(7),vthousand(7);
	   //# define INF 1000000;
int main()
{
    ll n,k;cin>>n;cin>>k;
	vector<ll> v(n);
	 for(ll i=0;i<n;i++)
     {
         cin>>v[i];
     }
	 vector<ll> dp(k+1,0);

	   sort(all(v));
	   dp[0]=0;
	    for(ll i=1;i<=k;i++)
        {
            ll j=0;
             while(j<n)
             {
                if(i-v[j]>=0){if(dp[i-v[j]]==0){dp[i]=1;break;}}
                else if(i-v[j]<0)break;
                j++;
             }
        }

	  if(dp[k])cout<<"First";
	   else cout<<"Second";
	return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N=3e3+55;
ll dp[N][N];
ll a[N];
int n;
	

int main()
{
	memset(dp,-1,sizeof dp);
	ios::sync_with_stdio(false);
	cin>>n;
	int t=(n%2)*2-1;
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int k=0,i=0,j=0;;i++,j++)
	{
		if(i==n)
		{
			k++;
			i=k;
			j=0;
			t*=-1;
		}
		if(k==n)
		break;
		if(i==j)
		{
			dp[i][j]=a[i]*t;
			continue ;
		}
		dp[i][j]=max(t*(dp[i-1][j]+t*a[i]),t*(dp[i][j+1]+t*a[j]));
		dp[i][j]*=t;
	}
	cout<<dp[n-1][0]<<endl;
	return 0;
}


Measured memory_bytes: 73216
n, a = int(input()), list(map(int, input().split()))
tf, count = True, -1
while tf:
  count += 1
  for s in range(n):
    if a[s] % 2 == 0:
      a[s] = a[s] / 2
    else:
      tf = False
      break
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const long long N = 2000 + 20;
long long a[N], ans = 1ll * 1000 * 1000 * 1000 * 1000 * 1000, b[N];
int main() {
	long long n, x;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i], b[i] = ans;
	}
	for (int i = 0; i <= n; i++) {
		long long ps = 0;
		for (int j = 0; j < n; j++) {
			long long y = ((j - i) + n) % n;
			b[j] = min(b[j], a[y]);
			ps += b[j];
		}
		ans = min(ans, x * i + ps);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_A&lang=jp

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

#define MAX_V 100000

vector<int> g[MAX_V];
int depth[MAX_V], parent[MAX_V];

void dfs(int u, int p, int d) {
	depth[u] = d;
	parent[u] = p;
	for (auto v : g[u]) {
		dfs(v, u, d + 1);
	}
}

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<bool> used(n, false);
	for (int i = 0; i < n; ++i) {
		int id; cin >> id;
		int k; cin >> k;
		while (k--) {
			int c; cin >> c;
			used[c] = true;
			g[id].push_back(c);
		}
	}

	int root = -1; {
		for (int i = 0; i < n; ++i) {
			if (not used[i]) root = i;
		}
		assert(root != -1);
	}

	dfs(root, -1, 0);
	for (int i = 0; i < n; ++i) {
		printf("node %d: parent = %d, depth = %d, ", i, parent[i], depth[i]);
		if (i == root) printf("root");
		else if (g[i].size() == 0) printf("leaf");
		else printf("internal node");
		printf(", [");
		for (int j = 0; j < g[i].size(); ++j) {
			printf("%d%s", g[i][j], ((j != g[i].size() - 1) ? ", " : ""));
		}
		printf("]\n");
	}
	return 0;
}



Measured memory_bytes: 6944
#include<iostream>
#include<vector>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a)
	{
		return parent[a]!=a?parent[a]=find(parent[a]):a;
	}
	bool same(int a,int b)
	{
		return find(a)==find(b);
	}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
};
int N;
vector<int>G[1<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int x,y;cin>>x>>y;
		x--,y--;
		G[x].push_back(y);
	}
	UF uf(1<<17);
	for(int i=0;i<1<<17;i++)
	{
		for(int j=0;j+1<G[i].size();j++)
		{
			uf.unite(G[i][j],G[i][j+1]);
		}
	}
	long ans=0;
	for(int i=0;i<1<<17;i++)
	{
		if(!G[i].empty())
		{
			ans+=uf.rank[uf.find(G[i][0])];
		}
	}
	cout<<ans-N<<endl;
}


Measured memory_bytes: 5888
N = int(input())
city = dict()
restaurants = []
for _ in range(N):
    s, p = input().split()
    restaurants.append([s, int(p)])
    if s in city.keys():
        city[s].append(int(p))
    else:
        city[s] = [int(p)]

city = sorted(city.items(), key=lambda x:x[0])

for c in city:
    points = c[1]
    points.sort(reverse=True)
    for p in points:
        for i in range(N):
            s = c[0]
            r = restaurants[i]
            if r[0] == s and r[1] == p:
                print(i + 1)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll A,B,C,X,Y,Z;
  cin>>X>>Y>>Z>>A>>B;
  int count=min(X+Y,2*Z)*min(A,B);
  if(A>=B)
  count+=(A-B)*min(X,2*Z);
  if(B>=A)
  count+=(B-A)*min(Y,2*Z);
  cout<<count<<endl;
}
  
  
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 9;
const int MAXN = 200005;
int n, q;
int a[MAXN], cnt[MAXN];
int v[MAXN];

struct seg{
	int tree[530000], cnt[530000];
	void upd(int s, int e, int ps, int pe, int p, int v){
		if(e < ps || pe < s) return;
		if(s <= ps && pe <= e){
			tree[p] += v;
			if(tree[p] == 0){
				if(ps == pe) cnt[p] = 0;
				else cnt[p] = cnt[2*p] + cnt[2*p+1];
			}
			else cnt[p] = pe - ps + 1;
			return;
		}
		int pm = (ps + pe) / 2;
		upd(s, e, ps, pm, 2*p, v);
		upd(s, e, pm+1, pe, 2*p+1, v);
		if(!tree[p]) cnt[p] = cnt[2*p] + cnt[2*p+1];
	}
}seg;

void update(int s, int e, int x){
	s = max(s, 1);
	seg.upd(s, e, 1, n, 1, x);
}

int emptyspot(){
	return n - seg.cnt[1];
}

int main(){
	scanf("%d %d",&n,&q);
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		cnt[a[i]]++;
	}
	for(int i=1; i<=n; i++){
		update(i - cnt[i] + 1, i, 1);
	}
	for(int i=1; i<=q; i++){
		int p, v;
		scanf("%d %d",&p,&v);
		update(a[p] - cnt[a[p]] + 1, a[p], -1);
		update(v - cnt[v] + 1, v, -1);
		cnt[a[p]]--;
		cnt[v]++;
		update(a[p] - cnt[a[p]] + 1, a[p], 1);
		update(v - cnt[v] + 1, v, 1);
		a[p] = v;
		printf("%d\n", emptyspot());
	}
}


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

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

  int n;
  cin >> n;

  int rem = 7, ans = 1;
  while (ans < 1e6) {
    rem %= n;
    if (!rem) {
      cout << ans << '\n';
      return 0;
    }
    rem = rem * 10 + 7;
    ++ans;
  }
  cout << -1 << '\n';
  return 0;
}


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

int	main()
{
	int	n;
	cin >> n;
	vector<int64_t>	a_vec(n);
	for (int i = 0; i < n; ++i)
		cin >> a_vec.at(i);
	int64_t	min_step;
	for (int j = 0; j < 2; ++j) {
		int	sign = 2 * j - 1;
		int64_t	sum = 0;
		int64_t	step = 0;
		for (int i = 0; i < n; ++i, sign *= -1) {
			sum += a_vec.at(i);
			if (sign * sum > 0)
				continue;
			step += - sign * sum + 1;
			sum = sign;
		}
		if (j == 0 || min_step > step)
			min_step = step;
	}
	cout << min_step << endl;
}


Measured memory_bytes: 1024
#pragma region Include/Defines
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <queue>
#include <time.h>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef vector<pii> vpii;
typedef vector <pll> vpll;
typedef long double ld;
#define all(a) std::begin(a), std::end(a)

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

template<typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); }
template<typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); }

#ifdef _DEBUG
#define epr(...) fprintf(stderr,__VA_ARGS__)
#else
#define epr(...) 
#endif
#pragma endregion

const int MAX = 1e5 + 10;
int n, a[MAX];

void clear() {
}

void read() {
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
}

void solve() {
	vector<int> v(MAX, 0);
	for (int i = 0; i < n; i++) {
		v[a[i]]++, v[a[i] + 1]++;
		if (a[i]) v[a[i] - 1]++;
	}

	int c = 0;
	for (int i = 0; i < MAX; i++)
		_max(c, v[i]);
	printf("%d\n", c);
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d", &n) == 1) {
		clear();
		read();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int a, b, m;
    cin >> a >> b >> m;
    vector<int> A(a), B(b);

    int ans = 0;
    int tmp = MOD;
    rep(i, a) {
        cin >> A[i];
        tmp = min(tmp, A[i]);
    }
    ans += tmp;
    tmp = MOD;
    rep(i, b) {
        cin >> B[i];
        tmp = min(tmp, B[i]);
    }
    ans += tmp;

    rep(i, m){
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, A[x-1] + B[y-1] - c);
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> B(N-1);
    for(int i = 0; i < N-1; i++){
      cin >> B.at(i);
    }
  long int out = B.at(0);
  out += B.at(N-2);
  for(int i = N-3; i > -1; i--){
    out += min(B.at(i+1), B.at(i));
  }
  cout << out;
}


Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cstdint>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

#define for_in(i, l, u) for (i = l; i <= u; ++i)
#define for_step(i, l, u, s) for (i = l; i <= u; i += s)
#define is_in(i, l, u) ((l) <= (i) && (i) <= (u))
#define times(N) for (int64_t itr##N = 0; itr##N < N; ++itr##N)

using namespace std;

int main()
{
    int64_t N, min = INT64_MAX;
    cin >> N;
    times(5)
    {
        int64_t i;
        cin >> i;
        if (i < min)
        {
            min = i;
        }
    }

    auto ceil_int = [](auto x, auto y) { return x / y + (x % y != 0); };
    auto ans = 4 + ceil_int(N, min);
    cout << ans << endl;
}

Measured memory_bytes: 256
/*==============================================*\
ID:          shahidul_brur

Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh

 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = 300005;
const int logn = 20;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
//    freopen("in_a.txt", "r", stdin);
//    freopen("out_a.txt", "w", stdout);
    int d, s, t;
    cin>>d>>s>>t;
    if(s*t>=d) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

int solve(vector<int> a,vector<int> b,int N){
    int c=0;
    for (int i = 0; i < N; i++) {
        if(a[i]==1) c++;
        if(b[i]==1) c--;
    }
    if(c!=0) return INF;

    int t=-1,ret=0;
    for(int i=0;i<N;i++){
        if(a[i]==1){
            for(int j=t+1;j<N;j++){
                if(b[j]==1){
                    t=j;
                    ret+=abs(j-i);
                    break;
                }
            }
        }
    }
    return ret;
}







int main(){
    int N,M;cin >> N >> M;
    vector<int> a(N),b,c; 
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < M; i++) {
        int t;cin >> t;
        for (int j = 0; j < t; j++) {
            b.pb(i%2?1:0);
            c.pb(i%2?0:1);
        }
    }
    cout << min(solve(a,b,N),solve(a,c,N)) << endl;
    return 0;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N;
	cin >> N;
	auto A = make_v<int64>(N, N-1);
	auto add = make_v<int64>(N, N);
	REP(i, N) {
	    REP(j, N-1) {
	        cin >> A[i][j]; A[i][j]--;
	    }
	}
	vector<int64> idx(N, 0);
	queue<PII> ok;
	REP(i, N) {
	    int64 opp = A[i][idx[i]];
	    if (i == A[opp][idx[opp]] && i < opp) {
	        add[i][opp] = add[opp][i] = 1;
	        ok.emplace(i, opp);
	    }
	}
	int64 res = 0, now = 0;

    while (ok.size()) {
        queue<PII> nxt;
        while (ok.size()) {
            int64 a, b;
            tie(a, b) = ok.front(); ok.pop();
            idx[a]++;
            idx[b]++;
            if (idx[a] < N-1) {
                int64 oa = A[a][idx[a]];
                if (!add[a][oa])
                    nxt.emplace(a, oa);
            }
            if (idx[b] < N-1) {
                int64 ob = A[b][idx[b]];
                if (!add[b][ob])
                    nxt.emplace(b, ob);
            }
        }
        while (nxt.size()) {
            int64 a, b;
            tie(a, b) = nxt.front(); nxt.pop();
            if (A[a][idx[a]] == b && A[b][idx[b]] == a) {
                if (!add[a][b]) {
                    ok.emplace(a, b);
                    add[a][b] = add[b][a] = 1;
                }
            }
        }
        res++;
	}
    REP(i, N) {
        if (idx[i] != N-1) {
            cout << -1 << endl;
            return 0;
        }
    }
	cout << res << endl;
}


Measured memory_bytes: 18048
#include <iostream>
#include <vector>

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

using namespace std;

int main() {
	int n;
	int min, ans;
	int sum1 = 0;
	int sum2 = 0;
	cin  >> n;
	
	vector<int> data(n);
	
	rep(i, n) {
		cin >> data.at(i);
	}
	
	rep(i, n) {
		sum1 += data.at(i);
		for (int j = i + 1; j < n; j++) {
			sum2 += data.at(j);
		}
		
		if (sum1 < sum2) {
			min = sum2 - sum1;
		} else {
			min = sum1 - sum2;
		}
		
		// 初回ループ時のみ
		if (i == 0) {
			ans = min;
		} else {
			if (ans > min) {
				ans = min;
			}
		}
		
		// sum2を初期化
		sum2 = 0;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#pragma warning(disable:4996)


int dfs(const vector<vector<int>>&edges, int now, int from, vector<int>ss) {
	if(now==ss[0])return 0;
	else if(now==ss[1])return 1;
	for (auto e : edges[now]) {
		if(e!=from)return dfs(edges,e,now,ss);
	}
	assert(false);
}
int main() {
	int N,M;cin>>N>>M;
	vector<vector<int>>edges(N);
	for (int i = 0; i < M; ++i) {
		int a,b;cin>>a>>b;a--;b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	bool ok=true;
	for (int i = 0; i < N; ++i) {
		if(edges[i].size()==0)ok=false;
		else if(edges[i].size()%2==1)ok=false;
	}
	if (ok) {
		bool aok=false;
		int num=0;
		for (int i = 0; i < N; ++i) {
			if(edges[i].size()>=6)aok=true;
			else if(edges[i].size()>=4)num++;
		}
		if(aok||num>=3)aok=true;
		else if (num == 2) {
			vector<int>ss;
			for (int i = 0; i < N; ++i) {
				if (edges[i].size() == 4) {
					ss.push_back(i);
				}
			}

			int to_same_num=0;
			for (int a = 0; a < 2; ++a) {
				int now=ss[a];
				for (auto e : edges[now]) {
					int to=dfs(edges,e,now,ss);
					if(a==to)to_same_num++;
				}
			}
			if(to_same_num==4)aok=true;
			else {
				assert(to_same_num==0);
				aok=false;
			}
		}
		else {
			//assert(false);
		}
		if (aok) {
			ok=true;
		}
		else {
			ok=false;
		}
	}
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s; cin>>s;
  int n=s.size();
  bool ok =true;
  for(int i=0;i<n-1;i++){
  if(s[i]==s[i+1]) ok=false; 
  }
  if(ok) cout<<"Good";
  else cout<<"Bad";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define   ll  long long
ll dp[105][100005];
int main()
{
    ll i,j,n,w,wt[105],val[105];
    cin>>n>>w;
    for(i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
    }
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(wt[i-1]<=j)
            {
                dp[i][j]=max((val[i-1]+dp[i-1][j-wt[i-1]]),dp[i-1][j]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w]<<"\n";
    return 0;
}



Measured memory_bytes: 80128
import re
import sys
from collections import *
from functools import lru_cache
from heapq import *
from itertools import *

INF=float('inf')

sys.setrecursionlimit(2**31-1)

rfs=lambda:rl().split()
ri=lambda:int(rl())
ris=lambda:list(map(int,rfs()))
rl=lambda:next(sys.stdin)
rls=lambda:list(map(str.strip,sys.stdin))
rs=lambda:rl().strip()
rt=lambda:sys.stdin.read()
rg=lambda:list(list(ln) for ln in rls())

def n4(i,j):
    return [
                (i-1,j),
        (i,j+1),        (i,j-1),
                (i+1,j),
    ]

def n8(i,j):
    return [
        (i-1,j-1),(i-1,j),(i-1,j+1),
        (  i,j-1),        (  i,j+1),
        (i+1,j-1),(i+1,j),(i+1,j+1),
    ]

inb=lambda i,j,m,n:0<=i<m and 0<=j<n

###########################################

H,W=ris()
s=rg()

nbl=sum(row.count('#') for row in s)
s[0][0]='#'
que=deque([(0,0,1)])
ok=False
while que:
    i,j,k=que.popleft()
    if i+1==H and j+1==W:
        ok=True
        break
    for ni,nj in n4(i,j):
        if inb(ni,nj,H,W) and s[ni][nj]!='#':
            s[ni][nj]='#'
            que.append((ni,nj,k+1))

if ok:
    print(H*W-nbl-k)
else:
    print(-1)


Measured memory_bytes: 10000
n,m = map(int,input().split())

pyl = []
pyl2 = [[] for i in range(n)]    
for i in range(m):
    p,y = map(int,input().split())
    pyl.append((p,y))
    pyl2[p-1].append((y,i))
    
argsortpyl = []
for p in pyl2:
    argsortpyl.append(sorted(p))
    

ansl = ["" for i in range(m)]

for idx, py in enumerate(argsortpyl):
    for ud,(y,i) in enumerate(py):
        ansl[i] = (idx+1, ud+1)
        
for x,y in ansl:
    print(str(x).zfill(6) + str(y).zfill(6))
    

Measured memory_bytes: 61188
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    m = defaultdict(int)
    for _ in range(N):
        A = int(input())
        m[A] += 1

    ans = 0
    for k, v in m.items():
        if v % 2 != 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15840
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;


/*Please dont change namespace, Dcoder 
and class must not be public*/

//Compiler version 4.0, .NET Framework 4.5


namespace Dcoder
{
public class Program
{
public static void Main(string[] args)
{
Method(args);
}

public static void Method(string[] args)
{
string s=Console.ReadLine();
long k=long.Parse(Console.ReadLine());
for(int i=0;i<s.Length;i++){
	if(s[i]!='1'||i==k-1){
	Console.WriteLine(s[i]);
	return;
	}else{
		continue;
	}
}
Console.WriteLine(k);
}
}
}

Measured memory_bytes: 11092
n,k = map(int,input().split())
ls = list(map(int,input().split()))
di = [0]*2001
sm = 0
ans = 0
cnt = 0
mod = 10**9+7
f = sorted(list(set(ls)))
for i in f:
    di[i] = sm
    sm += ls.count(i)
for j in range(n):
    for l in range(j+1,n):
        if ls[j] > ls[l]:
            cnt += 1
    ans += (cnt*k+di[ls[j]]*k*(k-1)//2)
    if ans >= 10**9+7:
        ans %= mod
    cnt = 0
print(ans)

Measured memory_bytes: 9340
fun main(args: Array<String>) {
    val K = nextInt()
    val ans = mutableListOf<Long>()
    (0 .. 9).forEach { ans.add(it.toLong()) }
    var p = 1
    while (p < K) {
        val x = ans[p++]
        for (a in -1 .. 1) {
            val d = x % 10 + a
            if (d < 0 || d > 9) continue
            ans.add(10 * x + d)
        }
    }
    println(ans[K])
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 40384
#include <bits/stdc++.h>
using namespace std;
int n, s, k;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k >> s;
for (int i=0; i<k; i++) cout << s << " ";
if (s==1) for (int i=0; i<n-k; i++) cout << "2 ";
else for (int i=0; i<n-k; i++) cout << s-1 << " ";
return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        int X = RInt();
        int dir = 0;
        int cnt = 0;
        while (true)
        {
            cnt++;
            dir += X;
            if (dir % 360 == 0) break;
        }
        WriteLine(cnt);
    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


Measured memory_bytes: 27504
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
	int N,an=0;
	cin >> N;
	vector<ll> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	vector<ll> c(N);
	for (int i = 0; i < N; i++) {
		cin >> c.at(i);
	}
	for (int i = 0; i < N; i++) {
		if (vec.at(i) > c.at(i)) {
			an += vec.at(i) - c.at(i);
		}
	}


	cout << an << endl;

	
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;


#[fastout()]
fn main(){
    input!{
        S:Chars,
    }
    let n=S.len();
    for i in 0..n-1{
        if S[i]==S[i+1]{
            println!("{} {}",i+1,i+2);
            return;
        }
    }
    for i in 0..n-2{
        if S[i]==S[i+2]{
            println!("{} {}",i+1,i+3);
            return;
        }
    }
    println!("-1 -1");
    return;
}

Measured memory_bytes: 2588
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  int mas[w+1];
  memset(mas,0,sizeof(mas));
  for(int i=0,sum=0,a;i<h;i++,sum=0){
    for(int j=0;j<w;j++){
      cin >> a;
      cout << (j!=0?" ":"") << a;
      sum += a;
      mas[j]+=a;
    }
    cout << " " << sum << endl;
    mas[w] += sum;
  }
  for(int i=0;i<=w;i++){
    cout << (i!=0?" ":"") << mas[i];
  }
  cout << endl;
}



Measured memory_bytes: 3108
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll a[100001];
	scan(N);
	rep(i,N){
		scan(a[i]);
	}
	rep(i,N){
		if(a[i]%2==1){
			prin("first");
			return 0;
		}
	}
	prin("second");
	return 0;
}


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

typedef pair<int, int> P;

int n;

vector<bool> visited(810);
vector<bool> isChild(810);
int childSum;

void dfsChild(int cv, vector<vector<P>> &G){
    visited[cv] = true;

    bool haveChild = false;
    for(auto x : G[cv]){
        int nv, ncost;
        tie(nv, ncost) = x;
        if(!visited[nv]){
            haveChild = true;
            dfsChild(nv, G);
        }
    }

    if(!haveChild){
        isChild[cv] = true;
        childSum += get<1>(G[cv][0]);
    }
}

vector<int> dijkstra(int s, vector<vector<P>> &G){
    vector<int> dist(n, 1e9);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);

    while(que.size()){
        int ccost, cv;
        tie(ccost, cv) = que.top();
        que.pop();

        if(dist[cv] < ccost) continue;

        for(auto x : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = x;

            if(isChild[nv]) continue;
            
            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    for(int i=0; i<n; i++){
        if(dist[i] == 1e9){
            dist[i] = -1;
        }
    }

    return dist;
}

signed main(){
    while(1){
        childSum = 0;
        for(int i=0; i<810; i++){
            visited[i] = false;
            isChild[i] = false;
        }

        cin>>n;
        if(n == 0) return 0;
        
        vector<int> p(n-1);
        for(int i=0; i<n-1; i++){
            cin>>p[i];
            p[i]--;
        }

        int sum = 0;
        vector<int> d(n-1);
        for(int i=0; i<n-1; i++){
            cin>>d[i];
            sum += d[i];
        }

        vector<vector<P>> G(n);
        for(int i=0; i<n-1; i++){
            G[i+1].emplace_back(p[i], d[i]);
            G[p[i]].emplace_back(i+1, d[i]);
        }

        int root = -1;
        for(int i=0; i<n; i++){
            if(1 < G[i].size()){
                root = i;
                break;
            }
        }

        dfsChild(root, G);

        vector<int> dist1 = dijkstra(root, G);
        int v1 = max_element(dist1.begin(), dist1.end()) - dist1.begin();
        vector<int> dist2 = dijkstra(v1, G);
        int diameter = *max_element(dist2.begin(), dist2.end());

        int rest = sum - (diameter + childSum);

        cout << childSum + diameter * 2 + rest * 3 << endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a, b, c;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    b.push_back(x);
  }
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    c.push_back(x);
  }
  
  sort(a.begin(), a.end()); sort(b.begin(), b.end()); sort(c.begin(), c.end());
  
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += (c.end()-upper_bound(c.begin(), c.end(), b[i])) * (lower_bound(a.begin(), a.end(), b[i])-a.begin());
  }
  cout << ans << endl;
}


Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int n; string s;
	cin >> n >> s;
	int answer = 0;
	Rep(i, n - 1){
		int count = 0;
		string p, q;
		p = s.substr(0, i);
		q = s.substr(i);
		vector<int> v;
		Rep(j, p.size()){
			int r = p[j] - 'a'; bool flag = false;
			Rep(k, v.size()){
				if(r == v[k]) flag = true;
			}
			if(flag) continue;
			v.pb(r);
			Rep(k, q.size()){
				if(q[k] - 'a' == r){
					count += 1;
					break;
				}
			}
		}
		answer = max(answer, count);
	}
	cout << answer << 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 __gnu_pbds;
using namespace std;
typedef long long ll;

const int mod=1e9+7;
const int inf=-1;
const int sz=2e5;

#define pi acos(-1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gap ' '
#define lb lower_bound
#define ub upper_bound
#define clr(x) memset(x,0,sizeof(x))
#define all(x) sort(x.begin(),x.end())
#define rall(x) reverse(x.begin(),x.end())
#define dbg puts("finding wrong")
#define case(x,y) printf("Case %lld: %lld\n",++x,y)
#define fastio ios::sync_with_stdio(false);cin.tie(0)


int ar[sz];

int main()
{
  fastio;
  ll a, b, c, ans, n;
  
  cin>>a>>b>>c;
  a=abs(a);
  n=a/c;
  ll m=min(n,b);
  a-=(m*c);
  n-=m;
  b-=m; 
  if(b%2==0)
  {
      cout<<abs(a)<<endl;
  }
  else cout<<abs(a-c)<<endl;
  
}


Measured memory_bytes: 3576
#include<iostream>

using namespace std;

int main(){
    
    int a,b,c;
    cin >> a >> b >> c;
    
    for(int i = 0;i < 2;i++){
        if(a > b){
            swap(a,b);
        }
        if(b > c){
            swap(b,c);
        }
    }
    
    cout << a << " " << b << " " << c << endl;
    
    return 0;
}



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

int main() {
  string S;
  cin>>S;
  int ans=0;
  for(int i=0;i<S.size();i++){
    if(i%2==0)if(S[i]=='p')ans--;
    if(i%2)if(S[i]=='g')ans++;
  }
  cout<<ans<<endl;
}


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

time_list = list(map(int,input().split()))

m = int(input())

drink_num_time = []
drink_time = []

for i in range(m):
    drink_num_time.append(list(map(int,input().split())))

normal_time = sum(time_list)


for i in range(m):
    drink_time.append(normal_time+drink_num_time[i][1]-time_list[(drink_num_time[i][0])-1])

for i in range(m):
    print(drink_time[i])


Measured memory_bytes: 9132
import java.util.Scanner;
public class Main{
  public static void main(String[]args){
    Scanner scan = new Scanner(System.in);
    int a,b,c,d;
    a=scan.nextInt();
    b=scan.nextInt();
    c=scan.nextInt();
    d=scan.nextInt();
    int tmp=Math.min(a,b)+Math.min(c,d);
    System.out.println(tmp);
  }
}

Measured memory_bytes: 21716
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Char
import Data.List


-- space delimited integers
getVals::IO [Int]
getVals = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

-- space delimited strings
getStrings::IO [String]
getStrings = (map BS.unpack . BS.words) <$> BS.getLine

main::IO()
main = do
    x:_<- getVals
    putStrLn $ if x >= 30 then "Yes" else "No"

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    ll N = S.length();

    if(S[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }

    ll check = 0;
    for(ll i=2; i<=N-2; i++){
        if(S[i] == 'C') check++;
    }
    if(check != 1){
        cout << "WA" << endl;
        return 0;
    }

    REP(i, N){
        if(isupper(S[i])){
            if(S[i] != 'A' && S[i] != 'C'){
                cout << "WA" << endl;
                return 0;
            }
        }
    }

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

Measured memory_bytes: 256
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

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

#define pb push_back;
#define endl "\n";
#define X first;
#define Y second;
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
vector<pii> adj[maxn];
ll n , v , u , w , dist[maxn];
void dfs(int v , int p)
{
    for(pii i : adj[v])
    {
        int u = i.X ; w = i.Y;
        if(u != p)
        {
            dist[u] = dist[v] + w;
            dfs(u , v);
        }
    }
}
int main() {
    migmig;
    cin>>n;
    for(ll i = 1 ; i < n ; i++)
    {
        cin >> v >> u >> w;
        adj[v].push_back({u , w});
        adj[u].push_back({v , w});
    }
 	dfs(1,1);
    for(ll i = 1 ; i <= n ; i++){
        cout << dist[i] % 2 << endl;	
	}
 
    return 0;
}



Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl v(n);
	rep(i,n)cin>>v[i];
	ll cur=v[0];
	ll ans=0,cnt=0;
	rep(i,n-1){
		if(v[i]>=v[i+1])cnt++;
		else cnt=0;
		cur=v[i];
		chmax(ans,cnt);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <algorithm>
using namespace std;
#include <cmath>
#include <string>
#define elif else if
int main(void) {
  int N;
  cin>>N;
  int A[2][100]={0};
  rep(i,2){
    rep(j,N) cin>> A[i][j];
  }

  int canndies[100] = {0};
  rep(i,N){
    rep(j,N){
      if( j<i){
        canndies[i] += A[0][j];
      }elif(j==i){canndies[i] += A[0][j]+A[1][j];
      }else{
        canndies[i]+=A[1][j];
      }
  }
}
  sort(canndies,canndies+N,greater<int>());
  
  cout<<canndies[0]<<endl;

  return 0;
}


Measured memory_bytes: 636
#include<bits/stdc++.h>
#define inf 999999999
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
int n,m;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int mp[25][25];
int book[25][25];
int ans=0;
void dfs(int step,int x,int y)
{
	if(x<0||x>n||y<0||y>m) return;
	if(book[x][y]<=step) return;
	if(!mp[x][y]) return;
	book[x][y]=step; 
	for(int i=0;i<4;i++) dfs(step+1,x+dx[i],y+dy[i]);
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		char ch;
		cin>>ch;
		if(ch=='.') mp[i][j]=1;
		else mp[i][j]=0;
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		if(!mp[i][j]) continue;
		memset(book,0x3f,sizeof(book));
		dfs(0,i,j);
		for(int k=1;k<=n;k++)
		for(int l=1;l<=m;l++)
		if(book[k][l]<=400) ans=max(ans,book[k][l]); 
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main(){
    int n;
    while(cin>>n){
        if(n==-1)break;
        double an,x=1,y=0;
        n--;
        while(n--){
            an=atan(y/x);
            if(x>0)an+=M_PI;
            an-=M_PI/2;
            x+=cos(an);
            y+=sin(an);
        }
        printf("%.2f\n%.2f\n",x,y);
    }
}

Measured memory_bytes: 1280