akhauriyash/Code-Regression huggingface dataset:
class dice:
    def __init__(self, pip):
        self.pip = pip
        
    def move(self,dir):
        if str(dir) == "E":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]
        elif str(dir) == "W":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]
        elif str(dir) == "N":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]
        elif str(dir) == "S":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]

n = int(input())
ans = "Yes"
ds =[]

for i in range(n):
    ds.append(dice(list(map(int,input().split()))))

for i in range(len(ds)-1):
    for j in range(i+1,len(ds)):
        d_tmp = dice(ds[j].pip)
        for op in "EEENEEENEEESEEESEEENEEEN":
            if ds[i].pip == d_tmp.pip:
                ans = "No"
                break
            d_tmp.move(op)

print(ans)

Measured memory_bytes: 7764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int X, Y;
    cin >> X >> Y;
    if (Y >= 2*X && Y <= 4*X && Y % 2 == 0) cout << "Yes";
    else cout << "No";
    return 0;
}


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

using namespace std;

int main()
{
  int n;
  cin>>n;
  vector<int> v(n);
  int count = 0;
  for(int i = 0;i<n;i++)
  {
      cin>>v[i];
      if((i+1) % 2 == 1 && v[i] % 2 == 1)
      {
          count++;
      }
  }

  cout<<count;
  
  
  return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int main(){

	int t=1;
	while(t--){
		int n,w;
		cin>>n>>w;
		long weight[n+1];
		long value[n+1];
		long dp[n+1][w+1];
		for(int i=1;i<=n;i++)
			cin>>weight[i]>>value[i];

		for(int i=0;i<=w;i++)
			dp[0][i]=0;
		for(int i=0;i<=n;i++)
			dp[i][0]=0;
		

		for(int i=1;i<=n;i++){
			for(int j=1;j<=w;j++){
				if(j-weight[i]>=0)
					dp[i][j]=max(dp[i-1][j],value[i]+dp[i-1][j-weight[i]]);
				else
					dp[i][j]=dp[i-1][j];
			}
		}
		// for(int i=0;i<=n;i++){
		// 	for(int j=0;j<=w;j++)
		// 		cout<<dp[i][j]<<" ";
		// 	cout<<endl;
		// }
		
		cout<<dp[n][w]<<endl;

		

	}
	return 0;
}

Measured memory_bytes: 79104
#include<iostream>
using namespace std;
int main()
{
    int n,i,num,sum=0;
    cin>>n;
    num=n;
    while(n>0)
    {
        i=n%10;
        n=n/10;
        sum=sum+i;
    }
    if(num%sum==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int a, b, c, d, e;
  int ans = 0;
  
  for (int i = 0; i <= N; i++){
    int x = i + 1;
    int tmp = a + b + c + d + e;
    
    a = x / 10000;
    x = x % 10000;
    
    b = x / 1000;
    x = x % 1000;
    
    c = x / 100;
    x = x % 100;
    
    d = x / 10;
    x = x % 10;
    
    e = x;
    
    if (A <= tmp && tmp <= B){
      ans = ans + i;
      continue;
    }
    
  }
  

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


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import collections
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N = int(input())
a = list(int(i) for i in input().split())
ans_list = []
ans = 0
for i in range(N):
	if a[N-1-i] == 1:
		ans += 1
		ans_list.append(N-i)
		chk = make_divisors(N-i)
		for j in range(len(chk)):
			a[chk[j]-1] = (1+a[chk[j]-1])%2
print(ans)
if len(ans_list) != 0:
	print(*ans_list)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=min((a), (b))

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, c[514], s[514], f[514];
	cin>>n;
	REP(i, n-1) cin>>c[i]>>s[i]>>f[i];
	REP(i, n-1){
		int ans=0;
		FOR(j, i, n-1){
			if(ans<=s[j]) ans=s[j];
			else if(ans%f[j]!=0) ans+=f[j]-ans%f[j];
			ans+=c[j];
		}
		cout<<ans<<'\n';
	}
	cout<<'0'<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
const double PI=3.141592;
int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  double R;
  cin >> R;
  double res = 2 * R * PI;
  cout << res << endl;
  


  return 0;
}


Measured memory_bytes: 3800
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed calc(string s){
  int n=(int)s.length();
  int half=n/2;
  int res=half;
  int buf=inf;
  if(n%2==0){
    rep(i,half){
      if(s[half-1-i]=='1'||s[half+i]=='1'){
        buf=i;
        break;
      }
    }
  }
  else{
    rep(i,half){
      if(s[half-i-1]=='1'||s[half+1+i]=='1'){
        buf=i+1;break;
      }
    }
    if(s[half]=='1'){
      buf=1;
    }
  }
  bool flag=true;
  rep(i,n){
    if(s[i]=='0'){
      flag=false;
      break;
    }
  }
  bool flag2=true;
  rep(i,n){
    if(s[i]=='1'){
      flag2=false;
      break;
    }
  }
  if(flag||flag2){
    res=0;buf=n;
  }
  int kkk=inf;
  rep1(i,n){
    int tmp=inf;
    if(s[i-1]!=s[i]){
      tmp=max(i,n-i);
    }
    kkk=min(kkk,tmp);
  }
  //res=kkk;
  int ex=0;
  char last='.';
  s+='0';
  int cur=0;
  rep(i,n+1){
    if(s[i]=='1'){
      cur++;
    }
    else{
      ex=max(ex,cur);
      cur=0;
    }
  }
  if(ex>=res+buf){
    res=0;buf=ex;
  }
  res+=buf;
  //cout<<res<<endl;
  return res;
}
int main(){
  string s;
  cin>>s;
  int res=calc(s);
  int n=s.length();
  rep(i,n){
    if(s[i]=='0'){
      s[i]='1';
    }
    else{
      s[i]='0';
    }
  }
  res=max(res,calc(s));
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 540
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 1e19;
#define all(v) v.begin(), v.end()

int main(){
  string A,B;
  cin >> A >> B;
  sort(all(A));
  sort(all(B));
  reverse(all(B));
  if(A<B){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}
      

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

string s,t;

void Input(){
	cin>>s>>t;
}

void Solve(){
	int minim=1e9;
	for(int i=0; i<=s.length()-t.length(); i++){
		int sum=0;
		for(int j=0; j<t.length(); j++){
			if(s[i+j]!=t[j])sum++;
		}
		minim=min(minim,sum);
	}
	cout<<minim<<'\n';
}

int main(){
	Input();
	Solve();
}

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

int main() {

    int s;
    cin >> s;
    int h, m, a;
    h = s / 3600;
    m = (s - h * 3600) / 60;
    a = (s - h * 3600 - m * 60);

    printf("%d:%d:%d\n", h, m, a);

}


Measured memory_bytes: 3208
#include<iostream>
using namespace std;
int main() {
	int n,a,b,c,d;
	for(int i=0;i<5;i++){
		c=0;
		d=0;
		cin>>n;
		if(n==0){
			break;
		}
		for(int y=0;y<n;y++){
			cin>>a>>b;
			if(a>b){
				c=c+a+b;
			}else if(b>a){
				d=d+a+b;
			}else{
				c=c+a;
				d=d+b;
			}
		}
		cout<<c<<" "<<d<<endl;
	}
return 0;
}


Measured memory_bytes: 2980
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(int argc, const char * argv[]) {
    
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<long long>v;
    v.push_back(a*c);
    v.push_back(a*d);
    v.push_back(b*c);
    v.push_back(b*d);
  
    cout<<*max_element(v.begin(),v.end());//-1000000000 0 -1000000000 0
    
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    ll n;
    cin >> n;
    if(n % 2 == 1) {
        cout << 0 << endl;
    } else {
        ll m = n / 2;
        ll fiv = 5;
        ll cfive = 0;
        while(m >= fiv) {
            cfive += m / fiv;
            fiv *= 5;
        }
        cout << cfive << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.valueOf(br.readLine());
		int ans=(int)(n+Math.pow(n, 2)+Math.pow(n, 3));
		System.out.println(ans);
	}
}


Measured memory_bytes: 32544
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
int n;
	string s;
	cin>>n;
	cin>>s;
	int r,b;
	r=0;b=0;
	rep(i,n){
		if(s[i] == 'R'){
			r++;
		}else{
			b++;
		}
	}
	cout<<(r>b?"Yes":"No")<<endl;
	return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

typedef valarray<int> vec;
typedef valarray<vec> mat;

bool check(mat &a){
	int n=a.size(),m=a[0].size();
	int r=0,c=0;
	rep(i,n-1){
		int index=-1;

		while(c<m&&index==-1){
			range(j,i,n) if(a[j][c]) index=j;
			if(index==-1)
				c++;
			else if(i!=index)
				swap(a[i],a[index]);
		}
		if(index==-1) break;

		range(j,i+1,n){
			int d=a[j][c]/a[i][c];
			range(k,c,m){
				a[j][k]+=a[i][k]*d;
				a[j][k]%=2;
			}
		}
		c++;
	}
	int rank=0,add=0;
	r=0,c=0;
	while(r<n&&c<m-1){
		while(c<m-1&&a[r][c]==0) c++;
		if(c==m-1) break;
		rank++,r++;
		while(r<n&&a[r][c]!=0) r++;
		if(r==n) break;
	}

	if(r<n) range(i,r,n) if(a[i][m-1]!=0) add=1;
	return !add;
}


int main(void){
	int m,n,d;
	while(cin >> m >> n >> d){
		int num=m*n;
		if(num==0) break;
		mat state(vec(0,num+1),num);
		rep(i,n)rep(j,m){
			int row=i*m+j;
			rep(a,n)rep(b,m){
				int col=a*m+b;
				int dist=abs(i-a)+abs(j-b);
				if(dist==d) state[row][col]=1;
			}
			state[row][row]=1;
			cin >> state[row][num];
		}
		cout << check(state) << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a[114514];
	cin>>n;
	REP(i, n){
		cin>>a[i];
	}
	if(n==1){
		cout<<1<<'\n';
		return 0;
	}
	int f=0, ans=1;
	REP(i, n-1){
		if(f==0){
			if(a[i]<a[i+1]){
				++f;
			}
			else if(a[i]>a[i+1]){
				--f;
			}
		}
		if(f==1){
			if(a[i]>a[i+1]){
				++ans;
				--f;
			}
		}
		else{
			if(a[i]<a[i+1]){
				++ans;
				++f;
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;


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

	int N;
	int i,j;
	int start;
	int end;
	bool flag=true;
	string S;
	string S1="";
	string S2="";

	cin >> S;

	N=S.size();
	
	S1=S.substr(0,N/2);
	S2=S.substr((N+3)/2-1,N-1);

	for(i=0;i<N/2;i++)
		if(S[i]!=S[N-1-i]) flag=false;

	if(flag && N==3){
		cout << "Yes" << endl;
		return 0;
	}

	N=S1.size();

	for(i=0;i<N/2;i++)
		if(S1[i]!=S1[N-1-i]) flag=false;

	for(i=0;i<N/2;i++)
		if(S2[i]!=S2[N-1-i]) flag=false;

	if(flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 3624
n = gets.to_i

input = []
n.times do |i|
  s,p = gets.chomp.split
  input[i] = [s,p.to_i,i+1]
end

input.sort_by!{|t| [t[0], -t[1]]}

input.each do |i|
    puts i[2]
end

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
ll a[505], k;
ll ans = 1;

void calc(ll m) {
    ll val[505];
    ll sum = 0;

    for (int j = 0; j < n; ++j) {
        auto x = a[j] % m;
        val[j] = x;
        sum += x;
    }

    std::sort(val, val + n, std::greater<ll>());

    ll res = sum;
    for (int i = 0, end = sum / m; i < end; ++i) {
        res -= val[i];
        res += m - val[i];
    }

    if (res <= 2 * k)
        ans = std::max(ans, m);
}

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

    std::cin >> n >> k;

    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];

        sum += a[i];
    }

    for (ll i = 1; i * i <= sum; ++i) {
        if (sum % i == 0) {
            calc(i);
            calc(sum / i);
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
const int MAX = 1000000;


int main(){
    int N, X, m[1000], min_gram;

    cin >> N >> X;
    for(int i = 0; i < N; i++){
        cin >> m[i];
        X -= m[i];
    }
    
    min_gram = m[0];
    for(int i = 1; i < N; i++){
        if(m[i] < min_gram) min_gram = m[i];
    }
    N += X / min_gram;
    cout << N << endl;    
	return 0;
}

Measured memory_bytes: 256
def resolve():
    from scipy.sparse.csgraph import floyd_warshall
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, m, l = map(int, input().split())
    inf = 10 ** 20
    ar = [[0] * n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        ar[a - 1][b - 1] = c
    x = floyd_warshall(ar, directed=False)
    br = [[0] * n for _ in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if x[i, j] <= l:
                br[i][j] = 1
    y = floyd_warshall(br, directed=False)
    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        p = y[s - 1, t - 1]
        print(int(y[s - 1, t - 1]) - 1 if y[s - 1, t - 1] < inf else -1)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 26944
(* 基本 *)
(* ocamlc str.cma main.ml でコンパイルできる *)
let () =
  let n = Scanf.sscanf (input_line stdin) "%d" (fun a -> a) in
  let ans = if n mod 2 == 0 then n / 2 else n / 2 + 1
  in
  print_int ans;
  print_newline ()


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

int main()
{
	long long a,b,c;
	cin>>a>>b>>c;
	if(a+b<c && 4LL*a*b<(c-a-b)*(c-a-b))printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ai = []
for i in range(0, n):
    ai.append(int(input()))

a_sorted = sorted(ai)
a_max = a_sorted[-1]
a_max2 = a_sorted[-2]
for i in range(0, n):
    if ai[i] == a_max:
        print(a_max2)
    else:
        print(a_max)


Measured memory_bytes: 14112
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#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);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n, x; cin >> n >> x;

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

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

	LL ans = 0;
	LL sum = 0;
	LL bufx = x;
	for (auto i : a) {

		sum += i;

		if (bufx - i >= 0) {
			++ans;
			bufx -= i;
		}
	}

	if (x > sum) {
		--ans;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007



              
int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    //freopen("error.txt", "w", stderr);
    #endif
      
    int t;
    t=1;
     //  cin>>t;
    while(t--){
          	ll n,a[100002],b[100003]={0},q,sum=0,l,r;
          	cin>>n;
          	REP(i,0,n-1){
          		cin>>a[i];
          		b[a[i]]++; sum+=a[i];
          	}
          	cin>>q;
          	REP(i,0,q-1){
          		cin>>l>>r;
          		sum+=(r-l)*b[l];
          		b[r]+=b[l];
          		b[l]=0;
          		cout<<sum<<"\n";
          	}
       


             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}


Measured memory_bytes: 5364
#include <cstdio>

using namespace std;
#define INF 1000000000

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

  for (int i = 0; i < N; ++i) {
    int B = 0, C = 0;
    bool ans = true;
    for (int j = 0; j < 10; ++j) {
      int A;
      scanf("%d", &A);
      int diffB = INF, diffC = INF;
      if (A > B) diffB = A - B;
      if (A > C) diffC = A - C;
      if (diffB == INF && diffC == INF) ans = false;
      if (diffB < diffC) B = A;
      else C = A;
    }
    if (ans) puts("YES");
    else puts("NO");
  }
}

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

#define sqr(x) ((x) * (x))

typedef struct point {
  double x;
  double y;
}Point;

int main(void)
{
  Point p1, p2;

  scanf("%lf %lf %lf %lf", &p1.x, &p1.y, &p2.x, &p2.y);

  printf("%f\n", sqrt(sqr(p2.x - p1.x) + sqr(p2.y - p1.y)));

  return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int trans(char c) {
    return c - 'A' + 1;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<int> vs(n + 1, 0), vt(m + 1, 0);
    REP(i, 0, n) {
        vs[i + 1] = (vs[i] + trans(s[i])) % 3;
    }
    REP(i, 0, m) {
        vt[i + 1] = (vt[i] + trans(t[i])) % 3;
    }
    int q;
    cin >> q;
    REP(i, 0, q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int mods = (vs[b] - vs[a - 1] + 9) % 3, modt = (vt[d] - vt[c - 1] + 9) % 3;
        cout << (modt == mods ? "YES" : "NO") << endl;
    }

    return 0;
}


Measured memory_bytes: 1744
n = int(input())
*A, = map(int, input().split())
a, b, c = A.count(1), A.count(2), A.count(3)
DP = [[[0.0 for k in range(n+1)] for j in range(n+1)] for i in range(n+1)]
for k in range(c+1):
    for j in range(b+c-k+1):
        for i in range(n-j-k+1):
            if i+j+k == 0:
                continue
            tmp = n
            if i > 0:
                tmp += DP[i-1][j][k]*i
            if j > 0:
                tmp += DP[i+1][j-1][k]*j
            if k > 0:
                tmp += DP[i][j+1][k-1]*k
            DP[i][j][k] = tmp/(i+j+k)
print(DP[a][b][c])


Measured memory_bytes: 260620
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scanf("%d %d", &N, &M)
	ac := make([]int, N+1)
	wa := make([]int, N+1)
	for i := 0; i < M; i++ {
		var p int
		var s string
		fmt.Scanf("%d %s", &p, &s)
		if s == "AC" {
			ac[p]++
		} else {
			if ac[p] == 0 {
				wa[p]++
			}
		}
	}
	count := 0
	penalty := 0
	for i := 0; i < N+1; i++ {
		if ac[i] > 0 {
			count++
			penalty += wa[i]
		}
	}
	fmt.Printf("%d %d\n", count, penalty)
}


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

import heapq

INF = float("inf")

def dijkstra(graph, st):
    n  = len(graph)
    ds = [INF]*n
    ds[st] = 0
    prevs = [None]*n
    
    qs = [(0, st)]

    while len(qs) > 0:
        d, nodeId = heapq.heappop(qs)
        
        if d > ds[nodeId]:
            continue
        
        for destId, length in graph[nodeId]:
            d2 = d + length
            if ds[destId] > d2:
                ds[destId] = d2
                prevs[destId] = nodeId
                heapq.heappush(qs, (d2, destId))
                
    return (ds, prevs)


def f(H, W, C, A):
    graph = [[(i, C[i][j]) for i in range(10)] for j in range(10)]
    ds, _ = dijkstra(graph, 1)

    return sum(ds[a] if a>= 0 else 0 for line in A for a in line)

    
def main():
    H,W = map(int, input().split())
    C = [list(map(int, input().split())) for i in range(10)]
    A = [list(map(int, input().split())) for i in range(H)]

    print(f(H,W,C,A))


if __name__ == '__main__':
    main()


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

using namespace std;

int a[301][301];
bool ok[301][301];

int main() {
    //ifstream cin("B.in");
    //ofstream cout("B.out");
    int i, n, j, k;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= n; j++)
            cin >> a[i][j];
    }
    for(i = 1; i <= n; i++)
        for(j = 1; j <= n; j++)
           if(i != j)
              for(k = 1; k <= n; k++)
                 if(i != k && j != k) {
                     if(a[i][k] + a[k][j] == a[i][j])
                        ok[i][j] = 1;
                     else if(a[i][k] + a[k][j] < a[i][j]) {
                        cout << -1;
                        return 0;
                     }
                 }
    long long sum = 0;
    for(i = 1; i <= n; i++)
        for(j = 1; j <= n; j++)
            if(ok[i][j] == 0 && i < j)
               sum += a[i][j];
    cout << sum;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 768
n,X =map(int,input().split())
count=0
for a in range(n+1):
    for b in range(n+1):
            if 10000*a + 5000*b + 1000*(n-a-b) == X and n-a-b >=0 and count == 0:
                print(a,b,n-a-b)
                count+=1
if count==0:
    print("-1 -1 -1")


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

using namespace std;

int main(){
    string s;cin>>s;
    int rj=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R'){
            rj++;
        }else if(rj>0 && s[i]=='S'){
            break;
        }
    }
    cout <<rj <<endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, b;
    cin >> a >> b;

    if(a>8||b>8)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;

}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    int ans=0;
    vi v(n);
    rep(i,n)cin>>v[i];
    for(int i=1; i<=n;i++){
        int index=i-1;
        if(v[index]!=i)continue;
        ans++;
        if(!index)swap(v[0],v[1]);
        else if(index==n)swap(v[n-1],v[n-2]);
        else{
            
            if(v[index]<v[index+1])swap(v[i],v[index]);
            else if(v[index]>v[index-1])swap(v[index],v[index-1]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int taxfree(int r, int p) {
  int i;
  for(i=p;i>0;i--) if(i*(100+r)/100 == p) break;
  return i;
}

int solve(int x, int y, int s){
  int a,b,da,db,i,max=0;
  for(a=1;a<s;a++){
    b=s-a;
    da = taxfree(x,a)*(100+y)/100;
    db = taxfree(x,b)*(100+y)/100;
    if(da+db > max) max=da+db;
  }
  return max;
}

int main(){
  int x,y,s;
  
  while(1){
    scanf("%d %d %d", &x, &y, &s);
    if(x==0 && y==0 && s==0) break;

    printf("%d\n", solve(x,y,s));
    /* printf("%d\n", taxfree(x,s)); */
  }
  
  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include<stdlib.h>

/*int compare(const void *a,const void *b){
  return *(int*)a-*(int*)b;
}*/


int main(){
	
	int N,M,a[60],b[60],i,load[60],j;
	scanf("%d",&N);
	scanf("%d",&M);
	
	for(i=0;i<M;i++){
		scanf("%d",&a[i]);
		scanf("%d",&b[i]);
	}
	
	for(i=1;i<N+1;i++){
		load[i]=0;
	}
	
	
	/*qsort(a,M,sizeof(int),compare);
	qsort(b,M,sizeof(int),compare);
	*/
	for(i=1;i<N+1;i++){
		for(j=0;j<M;j++){
		if(a[j]==i){
			load[i]++;
		}else if(b[j]==i){
			load[i]++;
		}
		
		}
		
	}
	
	for(i=1;i<N+1;i++){
	printf("%d\n",load[i]);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdint>
using namespace std;

int main() {
    int64_t x, k, d; cin >> x >> k >> d;

    int sign = 1;
    if (0 < x) sign = -1;

    int64_t n = min(abs(x) / d, k);
    x += sign * n * d;
    k -= n;

    if (k & 1) {
        x += sign * d;
    }

    cout << abs(x) << endl;
}



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


int arr[100005];
int dp[100005];

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

  dp[0] = 1e8;  
  // dp[1] = 0;
  for(int i=2;i<=n;i++)
    dp[i] = min(dp[i-2] + abs(arr[i] - arr[i-2]), dp[i-1] + abs(arr[i] - arr[i-1]));

  cout<<dp[n]<<endl;
  return 0;
}


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

int main() {
  long int N, Li = 1, Lj = 1, Lk = 2;
  cin >> N;

  for (int i = 2; i <= N; i++) {
    Li = Lj + Lk;
    Lk = Lj;
    Lj = Li;
  }

  cout << Li << endl;
}


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

int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	
	if(a+b > c+d) cout << "Left" << endl;
	else if(a+b == c+d) cout << "Balanced" << endl;
	else cout << "Right" << endl;
}

Measured memory_bytes: 256
//
// Created by yamunaku on 2019/09/07.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    vi a(1<<n);
    map<int,int> mp;
    rep(i,1<<n){
        cin >> a[i];
        mp[a[i]]++;
    }
    vi b;
    auto itr=mp.end();
    itr--;
    b.push_back(itr->first);
    itr->second--;
    if(itr->second==0) mp.erase(itr);
    rep(i,n){
        rep(j,1<<i){
            auto itr=mp.lower_bound(b[j]);
            if(itr==mp.begin()){
                CNO;
                return 0;
            }
            itr--;
            b.push_back(itr->first);
            itr->second--;
            if(itr->second==0) mp.erase(itr);
        }
    }
    CYES;
    return 0;
}


Measured memory_bytes: 14716
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
vector<int> to[200005];
vector<int>ans;
void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) {
			continue;
		}
		ans[u] += ans[v];
		dfs(u, v);
	}
}
int main() {
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ans.resize(n);
	for (int i = 0; i < q; i++) {
		int p, x;
		cin >> p >> x;
		p--;
		ans[p] += x;
	}
	dfs(0);
	for (int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 23552
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define mx 1000002
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main() {
	
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<"\n";
}	

Measured memory_bytes: 256
until (n = $<.gets.to_i).zero?
  table = n.times.map do |i|
    l = $<.gets.split.map(&:to_i)
    l + [l.sum]
  end
  last = (n + 1).times.map do |i|
    n.times.map {|j| table[j][i]}.sum
  end
  puts (table + [last]).map {|l| l.map {|i| sprintf("%5d", i)}.join }
end


Measured memory_bytes: 6932
while 2 > 1:
	line_num = int(raw_input())
	if line_num < 1:
		break
	mylist = [0,0,0,0,0,0,0,0,0,0,0]
	for n in range(line_num):
		dat = map(int, raw_input().split(" "))
		col_num = len(dat)
		row_sum = 0
		for m in range(col_num):
			mylist[m] += dat[m]
			row_sum += dat[m]
		mylist[col_num] = row_sum
		disp = ""
		for m in range(col_num):
			disp += ("%s" % dat[m]).rjust(5)
		disp += ("%s" % row_sum).rjust(5)
		print disp
	mylist[col_num] = 0
	for m in range(col_num):
		mylist[col_num] += mylist[m]
	disp_sum = ""
	for m in range(col_num + 1):
		disp_sum += ("%s" % mylist[m]).rjust(5)
	print disp_sum

Measured memory_bytes: 4268
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();

        System.out.println(solve(X, Y, Z));

        sc.close();
    }

    static String solve(int X, int Y, int Z) {
        return String.format("%d %d %d", Z, X, Y);
    }
}

Measured memory_bytes: 35736
#include <bits/stdc++.h>
#define int long long
#define ALL(c) begin(c),end(c)
using namespace std;
const int INF=1001001001001001001ll;
int N,T,Q;
vector<int> A,D;
vector<bool> done;
vector<int> ans;
int rec(int i) {
    int ret=INF;
    if(D[i]==2) {
        if(i!=0 && D[i-1]==1) {
            ret=A[i-1]+(A[i]-A[i-1])/2;
        }
        if(i!=0 && D[i-1]==2) {
            ret=rec(i-1);
        }
    }
    if(D[i]==1) {
        if(i!=N-1 && D[i+1]==1) {
            ret=rec(i+1);
        }
        if(i!=N-1 && D[i+1]==2) {
            ret=A[i]+(A[i+1]-A[i])/2;
        }
    }
    done[i]=true;
    return ans[i]=ret;
}
signed main() {
    cin>>N>>T>>Q;
    A=vector<int>(N);
    D=vector<int>(N);
    ans=vector<int>(N,INF);
    done=vector<bool>(N,false);
    for(int i=0; i<N; i++) {
        cin>>A[i]>>D[i];
    }
    for(int i=0; i<N; i++) {
        if(!done[i]) {
            rec(i);
        }
    }
    for(int i=0; i<Q; i++) {
        int x;
        cin>>x;
        x--;
        if(abs(ans[x]-A[x])>=T) {
            cout<<A[x]+(D[x]==1?T:-T)<<endl;
        }
        else {
            cout<<ans[x]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6708
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int N;
    cin >> N;
    vll A(N);
    cin >> A;
    int cnt2 = 0;
    int cnt4 = 0;
    int cnt = 0;
    REP(i,N){
        if(0 == A[i]%4)cnt4++;
        else if((0 == A[i]%2))cnt2++;
        else cnt++;
    }
    if((cnt == 0) || ((N == cnt + cnt4) && ((cnt4+1) >= cnt)) || (cnt4 >= cnt)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 4052
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i, q, a, b, r, len;
		String str, com, p, s1, s2, s3;
		str = sc.next();
		q = sc.nextInt();
		
		for (i = 0; i < q; i++) {
			com = sc.next();
			
			switch (com) {
			
			case ("print"):
				a = sc.nextInt();
				b = sc.nextInt();
				s1 = str.substring(a, b + 1);
				System.out.println(s1);
				break;
				
			case ("reverse"):
				a = sc.nextInt();
				b = sc.nextInt();
				s1 = str.substring(0, a);
				s2 = str.substring(a, b + 1);
				s3 = str.substring(b + 1);
				len = s2.length();
				
				for (r = len - 1; r >= 0; r--) {
					s1 += s2.substring(r, r + 1);
				}
				str = s1 + s3;
				break;
				
			case ("replace"):
				a = sc.nextInt();
				b = sc.nextInt();
				p = sc.next();
				s1 = str.substring(0, a);
				s2 = str.substring(a, b + 1);
				s3 = str.substring(b + 1);
				str = s1 + p + s3;
				break;
			default:
				break;
			}
		}
	}
}



Measured memory_bytes: 61984
#include<stdio.h>

int main(void){
    double num;
    int count;
    scanf("%lf",&num);
    if(num == 1 || num == 2) {
        count = 0;
    }else{
        count = ((num-1.0-1.0)/2.0)+0.5;
    }
    
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
from bisect import bisect_left
N, Q = map(int, input().split())
S = str(input())
LR = [list(map(int, input().split())) for i in range(Q)]

ans_list = []
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        ans_list.append(i-1)


for l, r in LR:
    i = bisect_left(ans_list, l-1)
    j = bisect_left(ans_list, r-1)
    print(j-i)

Measured memory_bytes: 75608
import java.util.Scanner;

class Main{




	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		
		int[] t = new int[n+1];
		for(int i = 1;i <= n;i++){
			t[i] = sc.nextInt();
		}
		
		int m = sc.nextInt();
		int[] p = new int[m+1];
		int[] x = new int[m+1];

		for(int i = 1;i <= m;i++){
			p[i] = sc.nextInt();
			x[i] = sc.nextInt();
		}

		for(int i = 1;i <= m;i++){
			int ans =0;

			for(int j = 1;j <= n;j++){
				if(j != p[i]){
					ans += t[j];
				}else{
					ans += x[i];
				}
			}
			System.out.println(ans);

		}



	}
}

class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 21844
#include <iostream>

int main()
{
    int in_second; // ??\??????????????????S 
    int out_hour, out_minute, out_second; // ?????????h:m:s

    // ??\???
    std::cin >> in_second;

    // ?????????????¨????
    out_second = in_second % 60; 
    out_minute = (in_second /60) % 60; 
    out_hour = (in_second / 60) /60;
    // ??????
    std::cout << out_hour << ":" << out_minute << ":" << out_second << std::endl;

    return 0;
}

Measured memory_bytes: 1168
N, M = map(int, input().split())
d=[[] for i in range(N)]
for i in range(M):
    b, c = map(int, input().split())
    d[b-1].append(c-1)
    d[c-1].append(b-1)
a=0
while True:
    count = 0
    for i in range(N):
        if len(d[i]) == 1:
            d[d[i][0]].remove(i)
            d[i]=[]
            count += 1
    if count == 0:
        break
    a+=count
print(a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,sum1,ans1=0,sum2,ans2=0;
	cin>>n;
	int a[n];
	int sum=0;
	for(int i=0;i<n;i++){
	   cin>>a[i];
	   sum+=a[i];
    }
	sum1=sum/n;
    for(int i=0;i<n;i++) ans1+=fabs(a[i]-sum1)*fabs(a[i]-sum1);
    sum2=sum/n+1;
	for(int i=0;i<n;i++) ans2+=fabs(a[i]-sum2)*fabs(a[i]-sum2);	
	if(ans1<ans2)
	   cout<<ans1;
	else
	   cout<<ans2;
}

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

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

    static class CMaximumVolume {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int l = s.nextInt();
            double d = l / 3.0;
            w.println(d * d * d);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 20436
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



int main()
{

int n ;
cin>>n;

string s,t;
cin>>s>>t;

for(int index = 0 ; index <n ; index++)
{
    cout<<s[index]<<t[index];
}
cout<<endl;

 return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  string A, B;
  cin >> A >> B;

  if(A.size()>B.size()){
    cout << "GREATER" <<endl;
  }else if(A.size()<B.size()){
    cout << "LESS" << endl;
  }else{
    if(A>B){
      cout << "GREATER" << endl;
    }else if(A<B){
      cout << "LESS" << endl;
    }else{
      cout << "EQUAL" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }



int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = k; i <= n + 1; i++){
    ll mn = i * (i - 1) / 2;
    ll mx = i * (2 * n - i + 1) / 2;
    ans += (mx - mn + 1) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define SYAMU(ary) memset(ary,0,sizeof(ary))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define eb emplace_back
#define mp make_pair

int n;
int k;
vector<char> D(12);

bool OK(string s) {
    rep(i, SZ(s)) {
        rep(j,k) {
            if(s[i] == D[j]) return false;
        }
    }
    return true;
}

int main() {
    while(cin>>n>>k) {
        D.clear();
        rep(i,k) cin >> D[i];

        for(int i = n; ; ++i) {
            string s = to_string(i);
            if(OK(s)) {
                cout << i << "\n";
                goto koko;
            }
        }
koko:
        n += 0;
    }

    return 0;
}


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

int main()
{
	map<int,char> f;
	map<char,int> g;
	for(int i=0;i<26;i++){
		f[i]='A'+i;
		f[26+i]='a'+i;
		g['A'+i]=i;
		g['a'+i]=26+i;
	}
	
	for(int n;cin>>n && n;){
		vector<int> ks(n);
		for(int& k:ks) cin>>k;
		string s; cin>>s;
		for(int i=0;i<s.size();i++){
			int j=g[s[i]];
			j=(j+52-ks[i%n])%52;
			cout<<f[j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1212
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var rDx2000 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var r = rDx2000[0];
            var D = rDx2000[1];
            var x2000 = rDx2000[2];

            var xi = x2000;
            foreach (var i in Enumerable.Range(0, 10))
            {
                xi = r * xi - D;
                Console.WriteLine(xi);
            }
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 13396