akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<tuple>
#include<sstream>
#include<functional>
#include<list>
#include<queue>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
typedef pair<ll, ll> p;
typedef vector<int> vec;
using Graph = vector<vector<int>>;
using graph = vector<vector<ll>>;


const ll inf = (1LL << 31) - 1;
const long long MOD = 1000000007;


int main() {
	int n, x, t;
	cin >> n >> x >> t;
	int a = n % x;
	int b = n / x;
	if (a != 0)b++;
	cout << b * t << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
#define size_t ll
ll n,ans=INT_MAX,s=0,t=0;
std::vector<int> a;
int main(){
  cin >> n;
  a.resize(n);
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  for (size_t i = 0; i < n-1; i++) {
    t += a[i]; s -= a[i];
    if(ans > abs(t-s))ans=abs(t-s);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
S = input()
N = len(S)
si, ei = 0, N-1
cnt = 0
while si<ei:
  if S[si] != S[ei]:
    if S[si] == 'x':
      si += 1
      cnt+=1
    elif S[ei] == 'x':
      ei -= 1
      cnt+=1
    else:
      print(-1)
      exit()
  else:
    si += 1
    ei -= 1
print(cnt)

Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int cnt=0;
	cnt+=n*(n-1)/2;
	cnt+=m*(m-1)/2;
	cout<<cnt<<endl; 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define x first
#define y second
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'


int main()
{
	ll x;
	cin>>x;
	ll curr=100;
	for(int i=1;;i++){
		curr=(curr+(curr/100));
		if(curr>=x){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

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

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

    vector<int> d(n+1) ;
    for (int i = 0; i < n; i++)
    {
        cin >> d.at(i) ;
    }
  	d.at(n)=1000;

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

    int ans = 1 ;

    for (int i = 1; i < n+1; i++)
    {
        if(d.at(i)>d.at(i-1) ){
            ans ++ ;
        }
    }
  	cout << ans-1 ;
    
    
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int br[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int a,b,m;
		cin>>a>>b>>m;
		
		int ans=1e18;
		for(int i =0 ;i < a;i++){
			cin >> ar[i];
		}
		for(int i =0 ;i < b;i++){
			cin >> br[i];
		
		}
		for(int i =0 ;i < m;i++){
			int x,y,z;
			cin>>x>>y>>z;
			--x;
			--y;
			if(x<a && y<b){
				ans = min(ans,ar[x]+br[y]-z);
			}
		}
		sort(ar,ar+a);
		sort(br,br+b);
		ans = min(ans,ar[0]+br[0]);
		cout<<max(0ll,ans)<<'\n';
	
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

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

using namespace std;

int main(){
    string str;
    cin >> str;

    bool flg[26];
    for(int i=0;i<26;i++)flg[i] = 0;
    for(int i=0;i<str.length();i++){
        for(int j=0;j<26;j++){
            if(str[i]==char(int('a')+j)){
                if(flg[j])flg[j] = false;
                else flg[j] = true;
            }
        }
    }
    for(int i=0;i<26;i++){
        if(flg[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

}


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

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        int[][] arrs = new int[n][2];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            arrs[i] = new int[]{x, y};
        }

        long[] arr = new long[n];
        long[] arr2 = new long[n];
        for (int i = 0; i < n; i++) {
            long x = arrs[i][0];
            long y = arrs[i][1];
            arr[i] = x + y;
            arr2[i] = x - y;
        }
        Arrays.sort(arr);
        Arrays.sort(arr2);

        System.out.println(Math.max(arr[n - 1] - arr[0], arr2[n - 1] - arr2[0]));

        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 73916
N=input()
S=input()
abc=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
out=[]
for i in S:
  idx=abc.index(i)
  idx=idx+int(N)%26
  if idx>25:
      idx-=26
  out.append(abc[idx])
out1=''.join(out)
print(out1)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> vv;


int main(){
  int n;
  cin >> n;
  vec a(n);
  rep(i,n) cin >> a[i];
  sort(a);
  cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int i;
	string a,b;
	cin>>a>>b;
	for(i=0;i<b.size();i++) cout<<a[i]<<b[i];
	if(a.size()!=b.size()) cout<<a[a.size()-1];
	return 0;
}


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

using namespace std;

int main(){
    int n;

    cin >> n;

    vector<int>v(n),ans(n,0);

    for(int i = 0;i < n-1;i++){
        cin >> v[i];
        ans[v[i]-1]++;
    }

    for(int i = 0;i < n;i++){
        cout << ans[i] <<endl;
    }

    return 0;
}

Measured memory_bytes: 4844
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[N];
        int[] v = new int[N];

        for(int i=0;i<N;i++){
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }
        long[][] dp = new long[N+1][W+1];
        for(int i=1 ;i<=N;i++ ){//items
            for(int j=1;j<=W;j++){
                long m ;
                if(j-w[i-1]>=0){
                    m = Math.max(dp[i-1][j-w[i-1]]+v[i-1], dp[i-1][j]);
                }else{
                    m =  dp[i-1][j];
                }
                dp[i][j]=m;
            }
        }
        System.out.println(dp[N][W]);
    }
}


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

int main() {
  long long A,B,C; cin>>A>>B>>C;
  if (A%2==0||B%2==0 || C%2==0) cout<< 0 << endl;
  else cout << min({A*B,B*C,C*A}) << endl;
}
  
  

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

int main()
{
    int n, d, ans = 0;
    cin >> n >> d;
    rep(i, n) {
        double x, y;
        cin >> x >> y;
        if (sqrt(x * x + y * y) <= d) 
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {

  int N;
  cin >> N;  

  string answer = "No";

  for (int i = 0; i <= N / 4; i++) {
    for (int j = 0; j <= N / 7; j++) {
      if (4 * i + 7 * j == N){
        answer = "Yes";
        break;
      }
    }
    if (answer == "Yes") {
      break;
    }
  }
  
  cout << answer << endl;

}

Measured memory_bytes: 256
#include <iostream>
//#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL w;
    LL h;
    LL n;
    cin >> w >> h >> n;
    LL x;
    LL y;
    LL a;

    LL max_x=w;
    LL min_x=0;
    LL max_y=h;
    LL min_y=0;

    for(LL i=0; i<n; i++){
        cin >> x >> y >> a;
        if(a==1){
            min_x=max(min_x,x);
        }else if(a==2){
            max_x=min(max_x,x);
        }else if(a==3){
            min_y=max(min_y,y);
        }else{
            max_y=min(max_y,y);
        }
    }

    if(min_x>=max_x || min_y>=max_y){
        cout << 0 << endl;
    }else{
        cout << (max_x-min_x)*(max_y-min_y) << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
a, b, c, k = input().split()
a = int(a)
b = int(b)
c = int(c)
k = int(k)

total = a + b + c
if k <= a:
    ans = k
elif k <= a + b:
    ans = a
else:
    ans = a + (-1)*(k-(a+b))
print(ans)


Measured memory_bytes: 9180
#include <iostream>
#include <cstring>
#include <cstdlib>

using namespace std;

int s,d,m;
int k[101];
int w[101][51];
int p[101][51];
int f[101];
int dp[5001][301];


int main(){
    while(cin >> s >> d >> m){
        memset(w, 0, sizeof(w));
        memset(p, 0, sizeof(p));
        memset(f, 0, sizeof(f));
        memset(dp, -1, sizeof(dp));
        for(int i=0;i<s;i++){
            cin >> k[i];
            for(int j=0;j<k[i];j++){
                cin >> w[i][j];
                cin >> p[i][j];
            }
        }
        for(int i=0;i<d;i++){
            cin >> f[i];
        }
        dp[0][0] = 0;

        int cnt = 0;
        for(int i=0;i<d;i++){
            for(int l=0;l<k[f[i]];l++){
                for(int j=0;j<=m;j++){
                    if(j+p[f[i]][l] <= m && dp[cnt][j] != -1){
                        dp[cnt+1][j+p[f[i]][l]] = max(dp[cnt+1][j+p[f[i]][l]],dp[cnt][j] + w[f[i]][l]);
                    }
                    dp[cnt+1][j] = max(dp[cnt+1][j], dp[cnt][j]);
                }
                cnt++;
            }
        }
        int maxw = 0;
        int minp = 0; 
        for(int i=0;i<=m;i++){
            if(maxw < dp[cnt][i]){
                maxw = dp[cnt][i];
                minp = i;
            }
        }
        cout << maxw << " " << minp << endl;
    }
}

Measured memory_bytes: 7092
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main() {
    val n = readLine()?.toInt() ?: return
    var z = 0
    var zoro = false
    repeat(n) {
        val (d1, d2) = intList()
        if (d1 == d2) {
            z++
            if (z == 3) {
                zoro = true
            }
        } else {
            z = 0
        }
    }
    if (zoro) {
        println("Yes")
    } else {
        println("No")
    }
}


Measured memory_bytes: 37824
n, w = map(int, input().split())
wt, v = [], []
for i in range(n):
    a, b = map(int, input().split())
    wt.append(a)
    v.append(b)
dp = [0 for i in range(w + 1)]
for i in range(len(wt)):
    for j in range(w, wt[i]-1, -1):
        dp[j] = max(dp[j], v[i] + dp[j - wt[i]])
print(dp[-1])


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

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int a,b,c,k,sum=0;
	cin>>a>>b>>c>>k;
	
	while(a>0 && k>0){
		sum = sum +1;
		k = k-1;
		a = a-1;	
	}

	while(b>0 && k>0){
		k = k-1;
		b = b-1;
	}

	while(c>0 && k>0){
		sum = sum -1;
		k = k-1;
		c = c -1;
	}

	cout<<sum;


	return 0;
}

Measured memory_bytes: 3672
import java.util.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		
		int b = sc.nextInt();
		
		int result = (a * b);
		
		if((result % 2) == 0) {
			System.out.println("Even");
		}else{
			System.out.println("Odd");
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  int ans=INF;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  for(int i=-100; i<=100; i++) {
    int num=0;
    rep(j,n) num+=(a[j]-i)*(a[j]-i);
    ans=min(ans,num);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
int dp[30][114514];
signed main(){
    int n,m;
    cin>>n>>m;
    vector<int> a;
    int cnt=0;
    int k=2;
    while(1){
        if(m==1){
            a.push_back(cnt);
            break;
        }
        if(k>1000000){
            if(cnt!=0)a.push_back(cnt);
            break;
        }
        if(m%k==0){
            m/=k;
            cnt++;
        }else{
            a.push_back(cnt);
            cnt=0;
            k++;
        }
    }
    if(m!=1)a.push_back(1);
    int ans=1;
    for(int i=0;i<30;i++){
        dp[i][0]=1;
    }
    for(int i=0;i<30;i++){
        for(int j=1;j<n;j++){
            if(i==0)dp[i][j]=1;
            else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }
    for(int i=0;i<a.size();i++){
        ans*=dp[a[i]][n-1];
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 33768
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;


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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n;i++){
    cin >> a[i];
  }
  int Xor = 0;
  for (int i = 0;i < n; i++){
    Xor = Xor ^ a[i];
  }
  for (int i = 0; i < n;i++){
    int x = Xor ^ a[i];
    cout << x << " ";
  }
  cout << '\n';
}

Measured memory_bytes: 4468
d,n = map(int, input().split())

if d == 0:
  if n == 100: print(101)
  else: print(n)
elif d == 1:
  if n == 100: print(10100)
  else: print(n*100)
else:
  if n == 100: print(100**2*100+10000)
  else: print(100**2*n)

Measured memory_bytes: 9116
#include<algorithm>
#include<cstdio>
using namespace std;

const int MAX_N = 2e5, A = 1e9 + 7;
int n;
int c[MAX_N];

int po(int x, int y) {
    int ans = 1;
    while (y > 0) {
        if (y & 1) ans = static_cast<long>(ans) * x % A;
        x = static_cast<long>(x) * x % A;
        y >>= 1;
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &c[i]);
    sort(c, c + n);
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = (ans + (po(2, 2 * (n - i - 1))
            + static_cast<long>(po(2, 2 * (n - i - 1) - 1))
            * (n - i - 1) % A) % A * po(2, 2 * i + 1) % A * c[i] % A) % A;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[1002][1002];
int dp[1002][1002];
int main(){
	int h, w, n;
	while(1){
	scanf("%d%d%d", &h, &w, &n);
	if(!h)break;
	fill((int*)a, (int*)(a+1002), 0);
	fill((int*)dp, (int*)(dp+1002), 0);
	for(int i = 1;i <= h;i++)
	for(int j = 1;j <= w;j++)scanf("%d", &a[i][j]);
	n--;dp[1][1] = n;
	for(int i = 1;i <= h;i++){
		for(int j = 1;j <= w;j++){
			dp[i][j] += dp[i][j-1]/2;
			if(a[i][j-1] == 1)dp[i][j] += dp[i][j-1]%2;
			dp[i][j] += dp[i-1][j]/2;
			if(a[i-1][j] == 0)dp[i][j] += dp[i-1][j]%2;
		}
	}
	
	int y = 1, x = 1, t, f;
	while(y <= h && x <= w){
		f = a[y][x];
		if(dp[y][x]%2)f = !f;
		if(f == 0)y++;
		else x++;
	}
	printf("%d %d\n", y, x);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

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

  int q;
  cin >> q;
  int T[q];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  int ans = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if(T[i] == S[j]) {
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3040
#include <iostream>
using namespace std;
//long long lofi[10]={0,1,32,243,1024,3125,7776,16807,32768,};
int main(){
	string s;
	cin>>s;
	long long k;
	cin>>k;
	k--;
	if(k==0){cout<<s[0]<<endl;return 0;}
	int lof1=0;
	while(s[lof1]=='1')lof1++;
	if(lof1>k){cout<<1<<endl;return 0;}
	cout<<s[lof1]<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

N, K = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]

r = 0
for idx, xi in enumerate(x):
    r = idx
    if xi >= 0:
        break

list = []

S = r - K
if x[r] == 0:
    S += 1
S = max(S, 0)

for s in range(S, r+1):
    e = s + K - 1
    if len(x) <= e:
        break
    list.append(abs(x[e] - x[s]) + abs(x[s]))
    list.append(abs(x[e] - x[s]) + abs(x[e]))

print(min(list))

sys.exit(0)


Measured memory_bytes: 14780
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n),dp;
	rep(i,n){
		cin>>a[i];
	}
	dp.push_back(a[0]);
	FOR(i,1,n){
		vector<int>::iterator itr;
		itr=lower_bound(dp.begin(), dp.end(), a[i]);
		if(itr==dp.end()){
			dp.insert(itr,a[i]);
		}else{
			dp.erase(itr);
			dp.insert(itr,a[i]);
		}
	}
	cout<<dp.size()<<endl;
}

Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



int main() {
    string s; cin >> s;
    map<char,int> mp;
    rep(i,s.size()){
        mp[s[i]]++;
    }
    if(mp['N'] && mp['W'] && mp['S'] && mp['E']) cout << "Yes" << endl;
    else if(mp['N'] && !mp['W'] && mp['S'] && !mp['E']) cout << "Yes" << endl;
    else if(!mp['N'] && mp['W'] && !mp['S'] && mp['E']) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
   ll a,b;char op;
   cin >>a>>op>>b;
   if(op=='+')cout <<a+b<<endl;
   else cout <<a-b<< endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    private static int dfs(int current, Set<Integer>[] graph, int[] counts){
        if(counts[current] == -1){
            counts[current] = 1;
        }
        int max = 0;
        if(graph[current] != null){
            for(int next : graph[current]){
                if(counts[next] == -1){
                    max = Math.max(max, dfs(next, graph, counts));
                }else {
                    max = Math.max(max, counts[next]);
                }
            }
        }
        counts[current] += max;
        return counts[current];
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int[] in = nextIntArray(br, 2);
        int n = in[0];
        int m = in[1];
        Set<Integer>[] graph = new HashSet[n];
        for(int i = 0; i < m; i++){
            int[] arr = nextIntArray(br, 2);
            if(graph[arr[0] - 1] == null) graph[arr[0] - 1] = new HashSet<>();
            graph[arr[0] - 1].add(arr[1] - 1);
        }
        int[] counts = new int[n];
        Arrays.fill(counts, -1);
        for(int i = 0; i < n; i++){
            if(counts[i] == -1){
                dfs(i, graph, counts);
            }
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            ans = Math.max(ans, counts[i]);
        }
        sb.append(ans - 1);
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}



Measured memory_bytes: 75352
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define MAX 100005
int N;
int x[100000],y[100000];

int d[100000];
int visited[MAX];
int vdx[MAX];
int vdy[MAX];

vector<int> X,Y;
map< int, vector<int> > gx, gy;

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i];
    X.push_back(x[i]);
    Y.push_back(y[i]);
    gx[ x[i] ].push_back(i);
    gy[ y[i] ].push_back(i);
    d[i]=1e9+1;
  }
  sort(X.begin(),X.end());
  X.erase( unique(X.begin(),X.end()) , X.end());
  sort(Y.begin(),Y.end());
  Y.erase( unique(Y.begin(),Y.end()) , Y.end());

  
  priority_queue< P , vector<P> , greater<P> > Q;
  d[0]=0;
  Q.push(P(0,0));
  
  while(!Q.empty()){
    P p=Q.top();Q.pop();
    int pos=p.second;
    if(visited[pos])continue;
    visited[pos]=true;

    int xid=lower_bound(X.begin(),X.end(), x[pos])-X.begin();
    if( vdx[xid]==0 ){
      vdx[xid]=1;
      for(int to:gx[ x[pos] ]){
        if(d[to]>0 && visited[to]==0){
          d[to]=0;
          Q.push( P(d[to],to) );
        }
      }
    }
    
    for(int nxid=xid-1;nxid<=xid+1;nxid+=2){
      if( nxid<0 || (int)X.size()<=nxid)continue;
      int to=gx[ X[nxid] ][0];
      int di=abs( X[nxid]-X[xid] );
      if( visited[to]==0 && di<d[to]){
        d[to]=di;
        Q.push( P(d[to],to) );
      }
    }
    
    int yid=lower_bound(Y.begin(),Y.end(), y[pos])-Y.begin();
    if( vdy[yid]==0 ){
      vdy[yid]=1;
      for(int to:gy[ y[pos] ]){
        if(d[to]>0 && visited[to]==0){
          d[to]=0;
          Q.push( P(d[to],to) );
        }
      }
    }

    for(int nyid=yid-1;nyid<=yid+1;nyid+=2){
      if( nyid<0 || (int)Y.size()<=nyid)continue;
      int to=gy[ Y[nyid] ][0];
      int di=abs( Y[nyid]-Y[yid] );
      if( visited[to]==0 && di<d[to]){
        d[to]=di;
        Q.push( P(d[to],to) );
      }
    }
  }
  long long ans=0;
  for(int i=0;i<N;i++){
    ans+= (long long)d[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 26352
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

typedef vector<int>      vi;
typedef pair<int,int>    ii;
typedef vector<vi>       vvi;
typedef vector<ii>       vii;
typedef long long        ll;

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int main( int argc, char * argv[] ){
  vector<string> C = {"Sunny", "Cloudy", "Rainy"};
  string str; cin >> str;
  int i;
  for(i=0 ; i < 3; ++i ){
    if( C[i] == str ){
      i = (i+1)%3;
      break;
    }
  }
  trace(i);
  cout << C[i] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve() {
    int a,b; cin>>a>>b;
    int t=1000000;
    int x1=max(b-a+1,-t),x2=min(b+a-1,t);
    for (int i = x1; i <= x2; ++i)
    {
        cout<<i<<" ";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int S;

int main(){
    cin>>S;

    int s1=S/100;
    int s2=S%100;

    string ans;
    if(1<=s1 && s1<=12 && 1<=s2 && s2<=12){
        ans="AMBIGUOUS";
    }else if(1<=s1 && s1<=12){
        ans="MMYY";
    }else if(1<=s2 && s2<=12){
        ans="YYMM";
    }else{
        ans="NA";
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
bool comp(p2 a,p2 b){
  return a.first>b.first;
}
void solve(){
  ll x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<p2> v;
  for(ll i=0;i<a;i++){
    ll x;
    cin>>x;
    v.push_back({x,0});
  }
  for(ll i=0;i<b;i++){
    ll x;
    cin>>x;
    v.push_back({x,1});
  }
  for(ll i=0;i<c;i++){
    ll x;
    cin>>x;
    v.push_back({x,2});
  }
  sort(v.begin(),v.end(),comp);
  ll n=ll(v.size());
  ll res=0,sum0=0,sum1=0;
  for(ll i=0;i<x+y;i++){
    if(v[i].second==0)
      sum0++;
    else if(v[i].second==1)
      sum1++;
  }
  if(sum0<=x&&sum1<=y){
    for(ll i=0;i<x+y;i++)
      res+=v[i].first;
  }
  else if(sum0>x){
    ll sum=0;
    for(ll i=0;i<x+y;i++)
    if(v[i].second==0){
      res+=v[i].first;
      sum++;
      if(sum==x)
        break;
    }
    sum=0;
    for(ll i=0;i<n;i++)
    if(v[i].second!=0){
      res+=v[i].first;
      sum++;
      if(sum==y)
        break;
    }
  }
  else{
    ll sum=0;
    for(ll i=0;i<x+y;i++)
    if(v[i].second==1){
      res+=v[i].first;
      sum++;
      if(sum==y)
        break;
    }
    sum=0;
    for(ll i=0;i<n;i++)
    if(v[i].second!=1){
      res+=v[i].first;
      sum++;
      if(sum==x)
        break;
    }
  }
  cout<<res;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll q=1;
  for(ll i=1;i<=q;i++)
    solve();
}

Measured memory_bytes: 10604
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int main(){

	int N, L[205];
	cin>>N;
	for(int i=0; i<2*N; i++){
		cin>>L[i];
	}

	sort(L,L+2*N);

	long long sum = 0;
	for(int i=0; i<2*N; i += 2){
		//if(i+1 == N) break;
		sum += min(L[i], L[i+1]);
	}

	cout<<sum<<endl;

	return 0;
}

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

alice = 0
bob = 0

for i in range(n):

    max_num = max(s)

    if i % 2 == 0:
        alice += max_num
    else:
        bob += max_num

    s.remove(max_num)

print(abs(alice - bob))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, a[100], p;
ll dp[100][2];
int main()
{
	scanf("%d%d", &n, &p);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			dp[i+1][j] += dp[i][j];
			if (a[i]%2) dp[i+1][!j] += dp[i][j];
			else dp[i+1][j] += dp[i][j];
		}
	}
	printf("%lld\n", dp[n][p]);
}

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

int main() {
  int N;
  cin >> N;
  using lint = long;
  auto lcm = [](lint a, lint b) { return a / __gcd(a, b) * b; };
  lint res;
  for (int i = 0; i < N; ++i) {
    lint a;
    cin >> a;
    res = i == 0 ? a : lcm(res, a);
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <unordered_set>
#include <stack>

using namespace std;

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

  string ans = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      ans = ans.substr(0, ans.size() - 1);
    } else {
      ans += s[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
vector<int> e[100010];
int u[100010], c[100010];
queue<int> q;
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i  = 0; i < m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        e[a].push_back(b);
        e[b].push_back(a);
    }
    q.push(1);
    int cnt  =1;
    u[1] = 1;
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (int i = 0; i < e[x].size(); i++) {
            int y = e[x][i];
            if (u[y] == 1) continue;
            c[y] = x;
            u[y] = 1;
            q.push(y);
            cnt++;
        }
    }
    if (cnt < n) {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    for (int i = 2; i<=n; i++) {
        printf("%d", c[i]);
        if (i!=n) printf("\n");
    }
    return 0;
}

Measured memory_bytes: 10444
n,m,Q=map(int,input().split())
LR=[]
ans=[]
for i in range(n):
    sub_list=[]
    for j in range(n):
        sub_list.append(0)
    LR.append(sub_list)
    ans.append(sub_list)
for i in range(m):
    l,r=map(int,input().split())
    LR[l-1][r-1]=LR[l-1][r-1]+1
for i in range(n)[::-1]:
    Sum=0
    for j in range(i,n):
        if i==j:
            ans[i][j]=LR[i][j]
            Sum=LR[i][j]
        else:
            Sum=Sum+LR[i][j]
            ans[i][j]=Sum+ans[i+1][j]
for i in range(Q):
    p,q=map(int,input().split())
    print(ans[p-1][q-1])
        

    


Measured memory_bytes: 59992
N=int(input())
S=input()

r=S.count('R')
g=S.count('G')
b=S.count('B')

cnt=0
for i in range(N):
    for j in range(i+1,N):
        k=j+j-i
        if k>=N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            cnt+=1

print((r*g*b)-cnt)


Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l.begin(), l.end(), greater<int>());
    int ans=0;
    for(int i = 0; i < k; i++)
    {
        ans+=l[i];
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%mod)
#define mod 1000000007
#define pb push_back
#define STREAM_FAST ios::sync_with_stdio(false)

using namespace std;
int a[107];
int main()
{
    int n;scanf("%d",&n);
    int sum=0;
    for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
    sort(a+1,a+1+n);
    a[0]=0;
    for (int i=0;i<=n;i++)
    {
        if ((sum-a[i])%10!=0)
        {
            sum-=a[i];
            break;
        }
    }
    if (sum%10==0) sum=0;
    printf("%d\n",sum);
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

#include <bits/stdc++.h>
#define rep(i,a,n) for(ll i = a;i < n;i++)
typedef long long ll;
using namespace std;


const ll MOD = 1e9+7;
 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;

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

    ll ans = 0,memo = 0;
    rep(i,0,n){
        if(s[i] == 'I'){
            memo++;
        }
        else{
            memo--;
        }
        ans = max(ans,memo);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3564
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  scanf("%d",&n);
  int a[n+1],b[n];
  REP(i,n+1) scanf("%d",&a[i]);
  REP(i,n) scanf("%d", &b[i]);
  int sub = min(a[0],b[0]);
  int sub2 = min(a[1],b[0]-sub);
  ll res = sub + sub2;
  FOR(i,1,n){
    sub = min(a[i]-sub2,b[i]);
    sub2 = min(a[i+1],b[i]-sub);
    res += sub + min(a[i+1],b[i]-sub);
  }
  cout << res << endl;
  
}

Measured memory_bytes: 1024
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

char vals['z'];
int A[100005];
int n;
ll cnv(ll base,string &val) {
    ll ret=0;
    ll mul=1;
    reverse(all(val));
    rep(i,val.size()) {
        ret+=mul*vals[val[i]];
        mul*=base;
    }

    return ret;

}
int main() {
    rep(i,10) vals[i+'0']=i;
    rep(i,26) vals[i+'A']=i+10;
    rep(i,26) vals[i+'a']=i+36;
    cin>>n;
    rep(i,n) {
        int p;
        string m;
        cin>>p>>m;
        A[i]=cnv(p,m);
    }
    int ans=0;
    rep(i,n) ans^=A[i];
    if(ans) cout<<"win"<<endl;
    else cout<<"lose"<<endl;
    return 0;
}

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

typedef long long ll;

ll N,A,B;
int main(){
	cin>>N>>A>>B;
	if(A>B){
		cout<<0<<endl;
	}else if(N==1 && A!=B){
		cout<<0<<endl;
	}else if (N<=2){
		cout<<1<<endl;
	}else{
		cout<<(N-2)*(B-A)+1<<endl;
	}
	return 0;
}

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

int32_t main(){
    int n, k, g, a;
    bool large = false;
    cin >> n >> k >> g;
    if( g >= k ) large = true;
    for(int i=1; i<n; i++){
        cin >> a;
        if( a >= k ) large = true;
        g = __gcd(g,a);
    }
    if( large && k % g == 0 ) cout << "POSSIBLE\n";
    else cout << "IMPOSSIBLE\n";
    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

res = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            sum = 500*i + 100*j + 50*k
            if sum == x:
                res += 1
print(res)


Measured memory_bytes: 3060
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>

typedef unsigned long long ULONG;
typedef long long LONG;
using namespace std;

#define PI 3.1415926535897932384626433
#define _DBG_

#define BIG 10000000000 //10

#define LAST 10000000 //10^7


LONG D;
vector<LONG> cost(26);
//vector<vector<ULONG>> sati(D + 1, vector<ULONG>(27));
vector<vector<LONG>> sati;
vector<LONG> answer;
vector<int> lastDate(26, -1);
LONG satVal = 0;


LONG calcSabunScore(int eventType, LONG date) {

	LONG sabun = sati[date][eventType];
	// costsum
	LONG costSum = 0;
	for (int i = 0; i < 26; i++) {
		if (i != eventType) {
			costSum += cost[i] * (date - lastDate[i]);
		}
	}

	sabun -= costSum;
	

	return sabun;

}


int main(void) {
	// for A

	cin >> D;

	vector<LONG> tmpans(D);
	answer = tmpans;


	for (int i = 0; i < 26; i++) {
		cin >> cost[i];
	}



	for (int d = 0; d < D; d++) {
		vector<LONG> tmpsati(26);
		for (int i = 0; i < 26; i++) {
			cin >> tmpsati[i];
		}
		sati.push_back(tmpsati);
	}
	// finish data input


	// answerを決める
	LONG totalScore = 0;
	for (int d = 0; d < D; d++) {
		int maxI = 0;
		LONG maxsabun = -1000000;
		for (int i = 0; i < 26; i++) {
			LONG sabun = calcSabunScore(i, d);
			if (sabun > maxsabun) {
				maxsabun = sabun;
				maxI = i;
			}
		}
		answer[d] = maxI;
		lastDate[maxI] = d;

		totalScore += maxsabun;

	}

	//randomchange
	int changeAtOnce = 2;
	int numChange = 10000;


	for (int c = 0; c < numChange; c++) {
		vector<LONG> answer2(D);

		for (int d = 0; d < D; d++)answer2[d] = answer[d];

		for (int cao = 0; cao < changeAtOnce; cao++) {
			int date = rand() % D;
			int newEvent = rand() % 26;

			answer2[date] = newEvent;
		}

			LONG totalScore2 = 0;

			// calc score
			for (int i = 0; i < 26; i++)lastDate[i] = -1;
			for (int d = 0; d < D; d++) {
				LONG sabun = calcSabunScore(answer2[d], d);
				totalScore2 += sabun;
				lastDate[answer2[d]] = d;
			}

			// これがよさそうならこれにする
			if (totalScore2 > totalScore) {
				totalScore = totalScore2;
				for (int d = 0; d < D; d++)answer[d] = answer2[d];
			}

		
	}


	// output
	for (int d = 0; d < D; d++) {
		cout << answer[d] + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3692
def factmod(n):
    tmp = 1
    for i in range(1,n+1):
        tmp *= i
        tmp %= (10**9+7)
    return tmp   
N,M = list(map(int,input().split()))
if abs(N-M) > 1:
    print(0)
    exit()
if N == M:
    print((2*(factmod(N)*factmod(M))%(10**9+7)))
else:
    print(factmod(N)*factmod(M)%(10**9+7))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

int main()
{

	long long sum=0;
	double num=0.0;
	int a,b,n=0;
	char c;

	while(cin>>a>>c>>b){
		sum+=a*b;
		num+=b;
		n++;
	}

	cout<<sum<<endl<<(long long)(num/n+0.5)<<endl;

	return 0;
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-
#ABC070C
import math

n = int(input())

t=[]
for i in range(0,n):
	t.append(0)
for i in range(0,n):
    t[i] = int(input())
t.sort()

sum=0
tmp=t[0]
tmpnum=1
for i in range(1,n):
	if(t[i]==tmp):
		tmpnum+=1
	else:
		tmp=t[i]
		sum+=tmpnum%2
		tmpnum=1
	if(i==n-1):
		sum+=tmpnum%2
print(sum)

Measured memory_bytes: 7396