akhauriyash/Code-Regression huggingface dataset:
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int main(){
  int N;
  cin >> N;
  int A;
  int Ans = 0;
  for(int i = 0; i < N; i++){
    cin >> A;
    Ans += A - 1;
  }

  printf("%d\n",Ans);
  return 0;

}


Measured memory_bytes: 256
def main():
    N = int(input())
    n = N % 10
    hon_list = [2, 4, 5, 7, 9]
    pon_list = [0, 1, 6, 8]
    if(n in hon_list):
        print("hon")
    elif(n in pon_list):
        print("pon")
    else:
        print("bon")
    

main()

Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
   
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
   
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
   
int main(){
  fastIO();
  int h,w,k,ans=0;
  cin>>h>>w>>k;
  char grid[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>grid[i][j];
    }
  }
  for(int row=0;row<pow(2,h);row++){
    for(int col=0;col<pow(2,w);col++){
      char temp[h][w];
      int cnt=0;
      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  temp[i][j]=grid[i][j];
	}
      }
      for(int bit=0;bit<h;bit++){
	if(row&(1<<bit)){
	  for(int i=0;i<w;i++){
	    temp[bit][i]='?';
	  }
	}
      }
      for(int bit=0;bit<w;bit++){
	if(col&(1<<bit)){
	  for(int i=0;i<h;i++){
	    temp[i][bit]='?';
	  }
	}
      }
      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  if(temp[i][j]=='#')cnt++;
	}
      }
      if(cnt==k)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

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

   string S;
   cin>>S;
   vector<int>a(S.size());
   for(int i=0;i<S.size();i++)cin>>S[i];
   for(int i=0;i<S.size();i++)a[i] = atoi(S.substr(i,1).c_str());
   int bit = pow(2,S.size()-1);
   for(int i=0;i<bit;i++){
      ll ans = a[0];
      for(int j=1;j<S.size();j++){
         if(i & (1<<(j-1))){
            ans += a[j];
         }
         else {
            ans -= a[j];
         }
      }
      if(ans == 7){
         for(int j=0;j<S.size();j++){
            cout<<S[j];
            if(j == S.size()-1)break;
            if(i & (1<<j))cout<<'+';
            else cout<<'-';
         }
         cout<<"=7"<<endl;
         return 0;
      }
   }
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
#include<set>
using namespace std;
int main(){


    int n;
    cin>>n;
    double T,A;
    cin>>T>>A;
    double mi=1e9;
    int ans=0;
    
    for(int i=0;i<n;i++){
        int h;
        cin>>h;
       double u=fabs((T-h*0.006)-A);
        if(mi>u){
            ans=i+1;
            mi=u;
        }
    }
    cout<<ans<<endl;
    




return 0;
}


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

H,W = map(int,input().split())
grid = tuple(tuple(map(lambda x: x=='.', input())) for _ in range(H))

dp = [[0]*(W+1) for _ in range(H+1)]
dp[0][1] = 1

for x in range(H):
  for y in range(W):
    if grid[x][y]:
      dp[x+1][y+1] = (dp[x][y+1] + dp[x+1][y])%MOD

print(dp[H][W])

Measured memory_bytes: 57820
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		System.out.println(0);

		String str1 = sc.next();
		if (str1.equals("Vacant")) {
			return;
		}

		recur(0, n, sc, str1, str1);

		return;
	}

	static void recur (int min, int max, Scanner sc, String leftGender, String rightGender) {

		int mid = (max+min)/2;
		System.out.println(mid);
		String str = sc.next();
		if(str.equals("Vacant")) {
			return;
		} else if (str.equals(leftGender) ^ ((mid-min)%2 == 0)) {
			recur(min, mid, sc, leftGender, str);
		} else {
			recur(mid, max, sc, str, rightGender);
		}

	}

}


Measured memory_bytes: 24356
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() {
    cin >> n;
    rep(i, n) {
        cin >> x;
        A.pb(x);
    }
}
void solve() {
    sort(all(A));
    reverse(all(A));
    priority_queue<ll> P;
    rep(i, n) {
        if(i) {
            x = P.top();
            ans += x;
            P.pop();
            P.push(A[i]);
            P.push(A[i]);
        } else
            P.push(A[i]);
    }

    print(ans);
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 7960
/* 
    @author : srinathbalaji_99
*/


#include<bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for(long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b)/GCD(a, b)
#define ff first
#define ss second
#define pall(a) REP(i, sizeof(a)/sizeof(a[0]))cout << a[i] << " ";cout << endl;
#define pvall(v) REP(i, v.size())cout << v[i] << " ";cout << endl;
#define gall(a, n) REP(i, n)cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;


using namespace std;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

LL dp[3001][3001];

int main()
{
    fast();



    LL t,n,i,j,k,x,y,c;
    string a, b;
    cin >> a >> b;
    n = a.size();
    LL m = b.size();
    REP(i, n + 1){
        REP(j, m + 1){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else{
                if(a[i - 1] == b[j - 1]){
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }
                else{
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
    }
    string ans = "";
    i = n;
    j = m;
    while(i > 0 && j > 0){
        if(a[i - 1] == b[j - 1]){
            ans += a[i - 1];
            i -= 1;
            j -= 1;
        }
        else{
            if(dp[i - 1][j] > dp[i][j - 1]){
                i--;
            }
            else{
                j--;
            }
        }
    }
    reverse(all(ans));
    cout << ans;
}

Measured memory_bytes: 70656
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
# initialize dp table by the value of 0
dp = [[0 for x in range(sum(C)+1)] for x in range(N+1)]

ans = 0
for i in range(N):
    for j in range(sum(C)+1):
        if j < C[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-C[i]] + (V[i] - C[i]))
            ans = max(ans, dp[i+1][j])
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    int n; cin >> n;
    string ans = "APPROVED";
    rep(i,n){
        int a; cin >> a;
        if(a % 2 == 0){
            if(a % 3 != 0 && a % 5 != 0){
                ans = "DENIED";
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> arr(n);
  map<int,long long> mp;
  for(auto &x: arr) {
    cin >> x;
    ++mp[x];
  }
  
  long long sum = 0;
  for(auto it: mp)
    sum += ((it.second * (it.second - 1)) / 2);
  
  for(auto x: arr) {
    long long res = sum;
    res -= (mp[x] - 1);
    
    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 10240
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;
// A - Multiplication 1
class Main{
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		BigDecimal A = sc.nextBigDecimal();

		BigDecimal B = sc.nextBigDecimal();

		BigDecimal w = A.multiply(B);

		BigDecimal ans = w.setScale(0, RoundingMode.DOWN);


		System.out.println(ans);
	}
}

Measured memory_bytes: 28984
w, a, b = map(int, input().split())
if a + w <= b:
    print(b - (a + w))
elif (b + w) <= a:
    print(a - (b + w))
elif a + w >= b > a:
    print(0)
elif b <= a and (b + w) <= (a + w):
    print(0)


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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

ll n, q, res = 0;
map<ll, ll> m;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; ++i){
        ll x; cin >> x;
        m[x]++;
        res += x;
    }
    cin >> q;
    while(q--){
        ll b, c;
        cin >> b >> c;
        auto it = m.find(b);
        if(it != m.end()){
            res -= it->s * it->f;
            res += it->s * c;
            ll cnt = it->s;
            m.erase(it);
            m[c] += cnt;
        }
        cout << res << "\n";
    }
    return 0;
}

Measured memory_bytes: 7524
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  long a, b, c=1, d=0, e, f, g, h, m, n;
  cin >> n;
  a=1e9+7;
  rep(i,1,n+1){
    c*=i;
    c%=a;
  }
  co(c);
    
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char name[101];
    cin>>name;
    if(strcmp(name,"hi")==0||strcmp(name,"hihi")==0||strcmp(name,"hihihi")==0||strcmp(name,"hihihihi")==0||strcmp(name,"hihihihihi")==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
mod = 998244353
N,S = map(int,input().split())
A = list(map(int,input().split()))

dp1 = [0]*(3001*N)
dp2 = [0]*(3001*N)

for n in range(N):
    for s in range(3000,-1,-1):
        dp2[n*N+s] = dp2[(n-1)*N+s]
        dp1[n*N+s] = dp1[(n-1)*N+s]
        if s>A[n]:
            dp2[n*N+s] += dp1[(n-1)*N+s-A[n]]*(N-n)
            dp1[n*N+s] += dp1[(n-1)*N+s-A[n]]
        elif s==A[n]:
            dp2[n*N+s] += (n+1)*(N-n)
            dp1[n*N+s] += n+1
        dp2[n*N+s] %= mod
        dp1[n*N+s] %= mod

print(dp2[(N-1)*N+S])

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

int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	int cells[H][W] = { 0 };
	// この時点で、全ての要素(=マス)が0(=白色)になっている.
	// ここから、該当部分を1(=黒色)にする.
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < W; j++) {
			cells[i][j] = 1;
		}
	}
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < H; j++) {
			//j行目i列目を消すので、cells[i][j]を1にしない.
			cells[j][i] = 1;
		}
	}

	int ans = 0;
	// 白色のマスの数を変数ansに入れていく.
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (cells[i][j] == 0) ans++;
		}
	}

	cout << ans << endl;
}

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

typedef long long ll;

int N;
ll W;
vector<ll> w, v;
vector<ll> DP;

int main()
{
    scanf("%d %lld", &N, &W);
    w.assign(N, 0);
    v.assign(N, 0);
    DP.assign(N*2005, 1<<30);

    DP[0] = 0;
    ll sol = 0;

    for(int i = 0; i < N; i++) {
        scanf("%lld %lld", &w[i], &v[i]);
        for(int j = N*1000; j >= 0; j--) {
            if(j==0 || DP[j] != 0) {
                DP[j+v[i]] = min(DP[j+v[i]], DP[j] + w[i]);
            }
        }
    }

    for(int i = N*1000; i >= 0; i--) {
        if(DP[i] <= W) {
            sol = i;
            break;
        }
    }

    printf("%lld\n", sol);

    return 0;
}


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

#define IOS std::cin.tie(0);std::ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>;

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 1e6+1;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(k,a,b);
    RepS(i,1,1000){
        if(a<=k*i&&k*i<=b){flag=true;break;}
        else flag=false;
    }
    printf(flag?"OK":"NG");

    return 0;
}

Measured memory_bytes: 3688
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String b = sc.nextLine();
            char[] a = b.toCharArray();
            for(int i = 0; i < 26; ++i) {
                for(int j = 0; j < a.length; ++j){
                    if('a' <= a[j] && a[j] <= 'z'){
                        if(a[j] == 'z') {
                            a[j] = 'a';
                        }else{
                            ++a[j];
                        }
                    }
                }
                String ans = String.valueOf(a);
                if(ans.contains("this") || ans.contains("that") || ans.contains("the") ){
                    System.out.println(ans);
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 18184
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(){
    vector<int> val(10);
    
    for(int i = 0; i < 10; ++i){
        scanf("%d", &val[i]);
    }
    
    sort(val.begin(), val.end(), greater<int>());
    
    for(int i = 0; i < 3; ++i){
        printf("%d\n", val[i]);
    }
    
    return 0;
}

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

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

#define MAXN 105

int n,m;
string a[MAXN];
ll dp[MAXN][MAXN][2];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n>>m;
	forn(i,0,n) cin>>a[i];
	
	forn(i,0,n) forn(j,0,m) forn(k,0,2) dp[i][j][k]=INF;
	dp[0][0][0]=dp[0][0][1]=(a[0][0]=='#'?1:0);
	
	forn(i,0,n) forn(j,0,m) forn(k,0,2)
	{
		if(a[i][j]=='.'){
			if(i>0) forn(k2,0,2) dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k2]);
			if(j>0) forn(k2,0,2) dp[i][j][k]=min(dp[i][j][k],dp[i][j-1][k2]);
		}
		else{
			if(i>0){
				if(a[i-1][j]=='.') dp[i][j][k]=min(dp[i][j][k], min(dp[i-1][j][0],dp[i-1][j][1])+1 );
				else dp[i][j][k]=min(dp[i][j][k], min(dp[i-1][j][0],dp[i-1][j][1]+1) );
			}
			if(j>0){
				if(a[i][j-1]=='.') dp[i][j][k]=min(dp[i][j][k], min(dp[i][j-1][0],dp[i][j-1][1])+1 );
				else dp[i][j][k]=min(dp[i][j][k], min(dp[i][j-1][0],dp[i][j-1][1]+1) );
			}
		}
	}
	
	/*forn(k,0,2){
		forn(i,0,n){
			forn(j,0,m){
				if(dp[i][j][k]>=INF) cout<<"IN ";
				else cout<<dp[i][j][k]<<" ";
			}
			cout<<'\n';
		}
		cout<<'\n';
	}*/
	
	cout<<min(dp[n-1][m-1][0],dp[n-1][m-1][1])<<'\n';
	
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>

#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace asl
{
    
    template <typename numeric_type>
    class point
    {
    public:
        numeric_type x, y;

        point(numeric_type x = 0, numeric_type y = 0) : x(x), y(y) {}

        point<numeric_type> &operator-=(const point<numeric_type> &ri)
        {
            x -= ri.x;
            y -= ri.y;
            return *this;
        }

    };

    template <typename numeric_type>
    std::istream &operator>>(std::istream &is, point<numeric_type> &p)
    {
        return is >> p.x >> p.y;
    }

    template <typename numeric_type>
    class line
    {
    public:
        point<numeric_type> p, q;

    };

    template <typename numeric_type>
    std::istream &operator>>(std::istream &is, line<numeric_type> &l)
    {
        return is >> l.p >> l.q;
    }

    template <typename numeric_type>
    using segment = line<numeric_type>;

    template <typename numeric_type>
    numeric_type cross(point<numeric_type> a, point<numeric_type> b)
    {
        return a.x * b.y - a.y * b.x;
    }

    template <typename numeric_type>
    numeric_type dot(point<numeric_type> a, point<numeric_type> b)
    {
        return a.x * b.x + a.y * b.y;
    }

    enum PointOrder
    {
        CounterClockwise = +1,
        Clockwise = -1,
        AlignedFirst = +2,
        AlignedLast = -2,
        AlignedIn = 0,
    };

    template <typename numeric_type>
    PointOrder ccw(point<numeric_type> a, point<numeric_type> b, point<numeric_type> c)
    {
        b -= a;
        c -= a;
        if (cross(b, c) > 0)
            return PointOrder::CounterClockwise;
        else if (cross(b, c) < 0)
            return PointOrder::Clockwise;
        else if (dot(b, c) < 0)
            return PointOrder::AlignedFirst; 
        else if (dot(b, b) < dot(c, c))
            return PointOrder::AlignedLast; 
        else
            return PointOrder::AlignedIn; 
    }

} 

#include <stdint.h>

#include <experimental/optional>

namespace asl
{
    
    template <typename numeric_type>
    bool intersect_segment_segment(const segment<numeric_type> &s, const segment<numeric_type> &t)
    {
        return ccw(s.p, s.q, t.p) * ccw(s.p, s.q, t.q) <= 0 && ccw(t.p, t.q, s.p) * ccw(t.p, t.q, s.q) <= 0;
    }

} 
 
#include <random>

#define endl '\n'

using namespace asl;
using namespace std;

void solve()
{
    segment<int> a, b;
    cin >> a >> b;

    cout << intersect_segment_segment(a, b) << endl;
}

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

    int t;
    cin >> t;

    for (int i = 0; i < t; ++i)
    {
        solve();
    }

    return 0;
}





Measured memory_bytes: 3216
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: usize,
        M: usize,
        SCs: [(usize, String); M],
    }

    for n in 0..1000 {
        if n.to_string().len() != N {
            continue;
        }

        let mut is_ok = true;
        for (s, c) in SCs.iter() {
            let ind: usize = s - 1;
            let strr: &str = &c;
            if &n.to_string()[ind..ind + 1] != strr {
                is_ok = false;
            }
        }

        if is_ok {
            println!("{}", n);
            return;
        }
    }

    println!("-1");
}


Measured memory_bytes: 2188
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
 
int main(){
    ll n;
    cin >> n;

    ll ansx,ansy,ansz;
    for(ll i=1; i<=n; i++){
        ll count = 0;
        for(ll x=1; x<=sqrt(i/6); x++){
            for(ll y=x; y<=sqrt(i/3); y++){
                //ll z = (-x-y+sqrt(-3*x*x-3*y*y-2*x*y+4*i))/2;
                for(ll z = y; z <= sqrt(i); z++){
                    if(x*x+y*y+z*z+x*y+y*z+z*x == i){
                        ansx = x;
                        ansy = y;
                        ansz = z;
                        if(ansx==ansy && ansy == ansz){
                            count += 1;
                        }
                        else if(ansx != ansy && ansy != ansz){
                            count += 6;
                        }
                        else{
                            count += 3;
                        }
                    }
                }
           }
        }
        cout << count << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int l, r, d, counter = 0;
    cin >> l >> r >> d;
    for (int i = d; i <= r; i += d)
    {
        if (i >= l)
        {
            counter++;
        }
    }

    cout << counter << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 2001;
const int two = 2;

int n, x, y, a[M], dp[two][M];

int main()
{   /*
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout); /**/
    cin.sync_with_stdio(0);
    cin >> n >> x >> y;
    for (int i = 0; i < n; i++)
        cin >> a[i + 1];
    a[0] = y;
    for (int i = n; i >= 1; i--)
        for (int d = 0; d < two; d++)
        {
            dp[d][i] = abs(a[n] - a[i - 1]);
            if (i == n)
                continue;
            for (int a = i + 1; a <= n; a++)
            {
                if (d == 0)
                    dp[d][i] = max(dp[1 - d][a], dp[d][i]);
                else
                    dp[d][i] = min(dp[1 - d][a], dp[d][i]);
            }
        }
    cout << dp[0][1];
    return 0;
}


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

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

    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){
        int D[n][n];
        REP(j, n){
            REP(k, n){
                D[j][k] = (j == k ? 0 : 1e9);
            }
        }
        REP(j, m){
            if(i == j) continue;
            D[A[j]][B[j]] = 1;
            D[B[j]][A[j]] = 1; 
        }
        REP(j, n){
            REP(k, n){
                REP(l, n){
                    D[k][l] = min(D[k][l], D[k][j] + D[j][l]);
                }
            }
        }
        bool f = false;
        REP(j, n){
            if(D[j][0] == 1e9){
                f = true;
                break;
            }
        }
        if(f) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
#  S = [[1st day], [2nd day],  ..., [D-th day]]
S = []
for i in range(D):
    Si = list(map(int, input().split()))
    S.append(Si)
I = 26

last = [0]*I

score = S[1]
contest = score.index(max(score))

last = [x+1 for x in last]
last[contest] = 0

print(contest + 1)

for day in range(1, D):
    score = [(last[i]*C[i])*I+S[day][i] for i in range(I)]
    contest = score.index(max(score))

    last = [x+1 for x in last]
    last[contest] = 0

    print(contest + 1)



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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    ll N, W; cin >> N >> W;

    vector<ll> w(N);
    vector<ll> v(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    ll dp[110][100100] = {0};

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (j + w[i] <= W) {
                dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i]);
            }
            
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }

    ll ans = 0;

    for (int i = 0; i <= W; ++i) {
        ans = max(ans, dp[N][i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 86272
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a==b)
    cout<<"Draw";
  else if(b==1 and a>1)
    cout<<"Bob";
  else if(a==1 and b>1)
    cout<<"Alice";
  else if(a>b)
    cout<<"Alice";
  else
    cout<<"Bob";
  system ("pause"); 
  return 0;
} 

Measured memory_bytes: 504
#include<stdio.h>

int main(){
    int a,b;
    long int base;
    int tmp;
    if(scanf("%d%d",&a,&b)!=2) return -1;
    base = ((long int)a*(long int)b);
    //printf("%d\n",a*b);
    //printf("%d\n",100000*99999);
    while(a%b!=0){
        tmp = a;
        a = b;
        b = tmp%b;
    }
    //printf("%ld,%d\n",base,b);
    printf("%ld\n",base/(long int)b);
    return 0;
}


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

int N;
int main() {
  cin >> N;
  int* di1 = new int[N];
  int* di2 = new int[N];
  for (int i=0;i<N;i++)
    cin >> di1[i] >> di2[i];
  int count=0;
  for (int i=0;i<N;i++){
    if(di1[i] == di2[i]) {
      count++;
      if (count == 3) {
        cout << "Yes";
        return 0;
      }
    } else {
      count =0;
    }
  }
  cout << "No";
}


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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){

  ll N = il();
  ll ans = 0;
  rep(i, N){
    ll a = il();
    ll num = i+1;
    if (a%2==1 && num%2==1) ans++;
  }

  cout << ans << endl;

}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];

int main() {
	int n;
	int d[50];
	cin>>n;
	rep(i,n){
		cin>>d[i];
	}
	int r=0;
	rep(i,n-1){
		for(int j=i+1;j<n;++j){
			r+=d[i]*d[j];
		}
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 4992
r=lambda x:x if u[x]<0else r(u[x])
(n,m),_,*e=[map(int,t.split())for t in open(0).readlines()]
u=[-1]*-~n
a=[n*~-n//2]
for x,y in e[::-1]:
 t=a[-1];x,y=sorted((r(x),r(y)))
 if x!=y:t-=u[x]*u[y];u[x]+=u[y];u[y]=x
 a+=[t]
print(*a[::-1],sep='\n')

Measured memory_bytes: 55916
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = input()
    if int(n) > int(n[0]*3):
        print((int(n[0])+1) * 111)
    else:
        print(int(n[0]*3))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}

int main() {
  int n; cin>>n;
  ll an=0;
  for(int a=1;a<n;a++) {
    an+=(n-1)/a;
  }
  cout<<an<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;



int main(){
      string s;
      cin>>s;
      bool t1=s.size()&1;
      bool t2=(*(s.begin())!=*(s.end()-1));
      if(t1^t2) cout<<"Second"<<endl;
      else cout<<"First"<<endl;
      return 0;
}

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

int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;

	for(int i=0; i<s.size(); i++){
		cout<<(char)((s[i]-'A'+n)%26+'A');
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SE second
#define FI first
vector <pair<int,char> > ss;
string str;
int ans,lim,j;

int main(){
    cin >> str;
    for(int i=1;i<=str.size();i++){
        if(str[i-1]==str[i]){
            for(j=1;j<str.size();j++){
                if(str[i+j-1]==str[i+j]);
                else break;
            }
           // cout << str[i-1] << endl;
            ss.push_back(make_pair(1+j,str[i-1]));
            i+=j;
        }else ss.push_back(make_pair(1,str[i-1]));
    }
   // printf("ss.size()=%d\n",ss.size());
    for(int i=2;i<ss.size();i++){
        if(ss[i-2].SE=='J'&&ss[i-1].SE=='O'&&ss[i].SE=='I'){
            //if(ss[i-2].FI==ss[i-1].FI&&ss[i-1].FI==ss[i].FI)ans=max(ans,ss[i].FI);
            if(ss[i-2].FI>=ss[i-1].FI&&ss[i].FI>=ss[i-1].FI)ans=max(ans,ss[i-1].FI);
        }

    }
    cout << ans << endl;

return 0;
}

Measured memory_bytes: 12504
# coding:utf-8
import math
a, b, h, m = map(int, input().split())

md = m // 5
md_min = m % 5
th = abs((30 * h + 0.5 * m) - (m * 6))

theta = min(th, 360 - th)
# print(theta)
ans = (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(theta))) ** 0.5
print(ans)


Measured memory_bytes: 9508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n;
    cin >> n;
    unordered_map<string, int> m;
    long ans = 0;
    while(n--){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if(m[s]) ans += m[s];
        m[s]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 10660
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
  hantei=10**9+1
  sp=set(p)
  ans=0
  for i in range(-10000,10000):
    if not i in sp:
      if hantei>abs(i-x):
        hantei=abs(i-x)
        ans=i
  print(ans)
else:
  print(x)

Measured memory_bytes: 9196
import math

n = int(input())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

f_inf = float('inf')



for p in range(1,5):
    sum1 = 0
    for i in range(n):
        tmp = abs(xlist[i] - ylist[i])**p
        sum1 += tmp
    
    if p == 4:
        maax = 0
        for i in range(n):
            maax = max(abs(xlist[i] - ylist[i]), maax)
        print(maax)
    else:
        print(sum1**(1/p))


Measured memory_bytes: 5700
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void swap(int &a, int &b){
	int c=a;
	a=b;
	b=c;
}
vector<int> v;

int main(){
	int w, n;
	cin >> w >> n;
	int a[n], b[n];
	string s;
	for(int i=0; i<n; i++){
		cin >> s;
		a[i] = stoi(s);
		while(1){
			if(s[0]!=',') s.erase(s.begin(), s.begin()+1);
			else{
				s.erase(s.begin(), s.begin()+1);
				break;
			}
		}
		b[i] = stoi(s);
	}

	v.resize(w);
	for(int i=0; i<v.size(); i++) v[i]=i+1;
	for(int i=0; i<n; i++){
		swap(v[a[i]-1], v[b[i]-1]);
	}

	for(int i=0; i<n; i++) cout << v[i] << endl;

	return 0;
}

Measured memory_bytes: 3164
def main():

    N,M = map(int,input().split())
    drinkList = [list(map(int,input().split())) for _ in range(N)]
    ans = 0
    stDrinkList=sorted(drinkList,key=lambda x: x[0])

    for i in stDrinkList:
        if M-i[1] <= 0:
            ans +=M*i[0]
            print(ans)
            exit()

        ans += i[0]*i[1]
        M -= i[1]


    






    
if __name__== "__main__":
    main() 




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

namespace AGC037A
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = CIN.String();

            long ans = 0;
            int beforeIndex = -1;
            char cur = '-';
            for (int i = 0; i < S.Length; i++)
            {
                if (i - 1 == beforeIndex && cur != S[i])
                {
                    beforeIndex = i;
                    cur = S[i];
                    ans++;
                    continue;
                }

                if (i - 2 == beforeIndex)
                {
                    beforeIndex = i;
                    cur = '-';
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 11616
X,K,D=map(int,input().split())
if abs(X) >= K*D:
    print(abs(X)-K*D)
else:
    y = abs(X)//D
    z = K-y
    X = abs(X) - (y*D)
    if z%2 == 0:
        print(abs(X))
    else:
        print(abs(X-D))


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

A = list(map(int,input().split()))
B = list(map(int,input().split()))

cnt = 0
for i in range(N):
    l =min(A[i],B[i])
    #A[i] -= l                       #残存モンスター数
    B[i] -= l                       #さらに勇者が倒せるモンスターの数
    cnt += l
    if B[i] > 0:                    #倒す余裕がある場合
        r = min(A[i+1],B[i])
        A[i+1] -= r                 #本来のA[i+1]から勇者が倒したモンスターrを引く
        #B[i] -= r
        cnt += r
print(cnt)

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

using namespace std;

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


int n;
int A[200005];
int cnt[25];
int chk() {
for(int i=0;i<25;i++) if(cnt[i]>=2) return 0;
return 1;
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>A[i];
    int j = 0;
    ll ans = 0;
    for(int i=1;i<=n;i++) {
        while(j<=n && chk()==1) {
            j++;
            for(int k=0;k<25;k++) {
                if((A[j]>>k) & 1) cnt[k]++;
            }
        }
        //cout<<i<<' '<<j<<'\n';
        ans += (ll)(j-i);
        for(int k=0;k<25;k++) {
            if((A[i]>>k) & 1) cnt[k]--;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>

const long long int MAX_V_SUM = 100001;
const long long int inf = 1e11;
const long long int MAX_N = 100;

int main(){
  // read problem
  long long int N, W, tmp_w, tmp_v;
  std::vector<long long int> w,v;
  
  scanf("%lld%lld", &N, &W);
  
  for(long long int i = 0; i < N; i++){
    scanf("%lld%lld", &tmp_w, &tmp_v);
    w.push_back(tmp_w);
    v.push_back(tmp_v);
  }
  
  // solve problem
  std::vector< std::vector<long long int> > table(N);
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j <= MAX_V_SUM; j++){
      table[i].push_back(inf);
    }
  }
  
  for(long long int i = 0; i < N; i++){
    table[i][0] = 0;
  }
  
  long long int max_value = 0;
  
  for(long long int j = 1; j <= v[0]; j++){
    table[0][j] = w[0];
    if(j > max_value && table[0][j] <= W){
      max_value = j;
    }
  }
  
  for(long long int i = 1; i < N; i++){
    for(long long j = 1; j <= MAX_V_SUM; j++){
      table[i][j] = table[i-1][j]; // the case where i-th item is not used
      if(j > v[i]){ // the case where i-th item is used
        table[i][j] = std::min(table[i][j], table[i-1][j-v[i]] + w[i]);
      }
      else{ //if(j <= v[i])
        table[i][j] = std::min(table[i][j], w[i]);
      }
      // update answer
      //std::cerr << "i:" << i << " j:" << j << " maxvalue:" << max_value << " tableij:" << table[i][j]<< std::endl;
      if(j > max_value && table[i][j] <= W){
        max_value = j;
      }
    }
  }
  
  /*for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j <= 20; j++){
      std::cerr << table[i][j] << " ";
    }std::cerr << std::endl;
  }*/
  
  std::cerr << "Answer:" << std::endl;
  std::cout << max_value << std::endl;
  
  return 0;
}


Measured memory_bytes: 79352
#include <stdio.h>

int main(void){

  int i,N,M;
  scanf("%d %d",&N,&M);
  int s[M],c[M];
  for(i=0;i<M;i++){
    scanf("%d %d",&s[i],&c[i]);
      }
  int K[N];

  int j;
  for(i=0;i<M-1;i++){
    for(j=i+1;j<M;j++){
      if(s[i]==s[j]&&c[i]!=c[j]){
	printf("-1");
	return 0;
	
      } 
    }
  }
  if(N==2){
    if(M==0){
	printf("10");
	return 0;
      }
    for(i=0;i<M;i++){
      if(s[i]==1&&c[i]==0){
	printf("-1");
	return 0;
      }
      
    }
  }

  if(N==3){
    if(M==0){
	printf("100");
	return 0;
      }
    for(i=0;i<M;i++){
      if(s[i]==1&&c[i]==0){
	printf("-1");
	return 0;
      }
    
    }
  }


    for(i=0;i<N;i++){
      K[i]=0;
    }
    if(N==2){

      K[0]=1;}
    else if(N==3){

      K[0]=1;}

    for(i=0;i<M;i++){
      K[s[i]-1]=c[i];
    }
    
    for(i=0;i<N;i++){
      printf("%d",K[i]);
    }
    
    
  return 0;
}


Measured memory_bytes: 128
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

S = sum(a)
cnt = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    if cnt.get(b):
        ans = S - b*cnt[b] + c*cnt[b]

        if cnt.get(c):
            cnt[c] += cnt[b]
            cnt[b] = 0
        else:
            cnt[c] = cnt[b]
            cnt[b] = 0
        S = ans
    print(S)

Measured memory_bytes: 21112