akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif




signed main(){
    int A, B, K;
    cin >> A >> B >> K;
    if(A>=K) {
        A-=K;
    }else{
        K-=A;
        A=0;
        B = max(0LL, B-K);
    }
    cout << A << " " << B << endl;
}


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

namespace ConsoleApp3
{
    internal class Class12
    {
        private static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            var max = string.Empty;
            var maxCount = 0;

            var count = s.Length - t.Length + 1;
            for (int i = 0; i < count; ++i)
            {
                if (i != 0)
                {
                    s = s.Substring(1);
                }
                max = s[0..t.Length];
                maxCount = Math.Max(maxCount, max.Select((x, i) => (x, i)).Count(x => x.x == t[x.i]));
            }

            Console.WriteLine(t.Length - maxCount);
        }
    }
}


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

int64_t ryuka(int n, vector<int64_t> &ryu){
  if(n == 0) return 2;
  if(n == 1) return 1;
  int64_t result = 0;
  if(ryu.at(n-1) != 0) result += ryu.at(n-1);
  else result += ryuka(n-1, ryu);
  if(ryu.at(n-2) != 0) result += ryu.at(n-2);
  else result += ryuka(n-2, ryu);
  ryu.at(n) = result;
  return result;
}

int main() {
  int N;
  cin >> N;
  vector<int64_t> ryu(N+1,0);
  cout << ryuka(N, ryu) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    long long H,W;
    cin>>H>>W;
    if(H%3==0||W%3==0){
        cout << 0 << endl;
        return 0;
    }
    //横T字その１
    long long left = W/3;
    long long right = W-left;
    long long leftb =H*left;
    long long Hhalf = H/2;
    long long rightupb = Hhalf*right;
    long long rightdob = (H-Hhalf)*right;
    long long Smax=max(max(leftb,rightupb),rightdob);
    long long Smin=min(min(leftb,rightupb),rightdob);

    long long ans = Smax-Smin;
    //  横T字その２
    left=W/3+1;
    right = W-left;
    leftb =H*left;
    rightupb = Hhalf*right;
    rightdob = (H-Hhalf)*right;
    Smax=max(max(leftb,rightupb),rightdob);
    Smin=min(min(leftb,rightupb),rightdob);

    ans = min(ans,Smax-Smin);
    //縦T字その１
    long long up = H/3;
    long long upb=up*W;
    long long down=H-up;
    long long Whalf = W/2;
    long long downrightb=Whalf*down;
    long long downleftb = (W-Whalf)*down;
    Smax=max(max(upb,downleftb),downrightb);
    Smin=min(min(upb,downleftb),downrightb);
    
    ans = min(ans,Smax-Smin);

    //縦T字その２
    up = H/3+1;
    upb=up*H;
    down=H-up;
    downrightb=Whalf*down;
    downleftb=(W-Whalf)*down;
    Smax=max(max(upb,downleftb),downrightb);
    Smin=min(min(upb,downleftb),downrightb);
    
    ans = min(ans,Smax-Smin);

    //縦3等分
    ans=min(ans,W);
    //横3等分
    ans=min(ans,H);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int i = 0;
	int n = s.size();
	
		//char x = s[s.size()- 1];
		if(s[n-1] == 's')
		{
		cout<<s<<"es";}
		else
		{
		cout<<s<<"s";}
	
}
   


Measured memory_bytes: 3608
#include <stdio.h>
#include <ctype.h>


int main(void) {
	
	char ch[1000];
	int a[1000]={0},i=0,j=0,k=0;
	
	while(1){
		scanf( "%c" , &ch[i] );
		if( ch[i] == '\n' ){
			i = 0;
			j++;
		} else if ( ch[0] == '0' ){
			a[j] = -1;
			break;
		} else {
			a[j] = a[j] + ch[i] - '0';
			i++;
		}
	}

	while(1){
		if( a[k] == -1 ){
			break;
		}
		printf( "%d\n" , a[k]);
		k++;
	}
	
	return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const int inf =1e9;
const int minus_inf = -1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n, k; cin >> n >> k;
    vector<int> dp(n, inf);
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    // initialization
    dp[0] = 0;
    if(k>=n){
        for(int i=1; i<=n; i++){
            dp[i] = abs(h[i]-h[0]);
        }
    }else{
        for(int i=1; i<=k; i++){
            dp[i] = abs(h[i]-h[0]);
        }
        for(int i=k; i<n; i++){
            for(int j=1; j<=k; j++){
                dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
const int INF = 1e9 + 7;

using namespace std;

int main(){
    cin.tie(0), ios::sync_with_stdio(false);
    ll n,m,ans;
    cin >> n >> m;
    if(n==1&&m==1) ans = 1;
    else if(n==1||m==1){
        ans = n*m-2;
    }else{
        ans = n*m-n-n-m-m+4;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int i,N;
    int cnt=0;
    scanf("%d",&N);
    for(i = 1 ; i <= N ; i++){
        if(i % 2 != 0){
            cnt++;
        }
    }
    printf("%f",(double)cnt/N);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int a;
    while(~scanf("%d",&a))
    {
        if(a%2==0)
            printf("%d\n",a);
        else
            printf("%d\n",a*2);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>

using namespace std;

int chp(char s[]){
    int i , n = strlen(s);
    for( i = 0; i <= (n/2); i++){
        if(s[i] != s[n - i - 1])break;
    }
    if(i == (n/2) + 1)return 1;
    else return 0;
}


int chp1(char s[]){
    int i, n = strlen(s) / 2;
    for( i = 0; i <= (n/2); i++){
        if(s[i] != s[n - 1 - i])break;
    }
    if(i == (n/2) + 1)return 1;
    else return 0;
}

int chp2(char s[]){
    int i, n = (strlen(s) / 2), m = strlen(s) ;
    for( i = 0; i <= (n/2); i++){
        if(s[i + n + 1] != s[m - 1- i])break;
    }
    if(i == (n/2) + 1)return 1;
    else return 0;
}

int main()
{
	char s[99];
	cin >> s;
	int N = strlen(s);
	if(chp(s) && chp1(s) && chp2(s))cout << "Yes" << endl;
	else cout<< "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a*c<=b)
    {
        cout<<c;
    }
    else if(a>b)
    {
        cout<<0;
    }
    else
    {
        cout<<b/a;
    }
}

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

int main() {
  int64_t N,M;
  cin >> N >>M;

  vector<int64_t> L(M);
  vector<int64_t> R(M);

  cin >> L.at(0) >> R.at(0);

  int64_t L_max,R_min;

  if(M==1){
    cout << R.at(0)-L.at(0)+1 <<endl;
  } 
  else{
  for(int i=1;i<M;i++){
    cin >> L.at(i) >> R.at(i);
    if(i==1){
      L_max=max(L.at(i),L.at(0));
      R_min=min(R.at(i),R.at(0));
    }
    L_max=max(L.at(i),L_max);
    R_min=min(R.at(i),R_min);


    if(R_min<L_max){
      cout << 0 <<endl;
      break;
    }
    if(i==(M-1)){
        cout << R_min-L_max+1 << endl;
    }
  } 


  } 




}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	if(a<=b&&b<=c){
		printf("%d %d %d\n",a,b,c);
	}

	else if(a<=c&&c<=b){
		printf("%d %d %d\n",a,c,b);
	}
	else if(b<=a&&a<=c){		printf("%d %d %d\n",b,a,c);
	}
	else if(b<=c&&c<=a){
		printf("%d %d %d\n",b,c,a);
	}
	else if(c<=a&&a<=b){
		printf("%d %d %d\n",c,a,b);
	}
	else if(c<=b&&b<=a){
		printf("%d %d %d\n",c,b,a);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector<double> vd;

int N;
vd P;
vector<vd> dp;

void input_init(void) {
	cin >> N;
	P.resize(N + 1);
	for (int i = 1; i <= N; ++i)
		cin >> P[i];
	dp.resize(N + 1, vd(N + 1, 0.0));
}

void calcu(void) {
	dp[1][0] = (1.0 - P[1]);
	dp[1][1] = P[1];
	for (int i = 2; i <= N; ++i) {
		for (int j = 0; j < i; ++j) {
			dp[i][j + 1] += dp[i - 1][j] * P[i];
			dp[i][j] += dp[i - 1][j] * (1.0 - P[i]);
		}
	}
}

int main(void) {
	input_init();
	calcu();
	double ans = 0.0;
	for (int i = N / 2 + 1; i <= N; ++i)
		ans += dp[N][i];
	cout << fixed << setprecision(12) << ans << '\n';
	return 0;
}


Measured memory_bytes: 70656
import sys
for line in sys.stdin.readlines():
  l = [int(i) for i in line.split(',')]
  v2 = l.pop()
  v1 = l.pop()
  d = sum(l) * v1 / (v1+v2)
  a = 0
  c = 0
  for i in l:
    a += i
    c += 1
    if d <= a:
      print(c)
      break

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


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx,avx2,sse4,tune=native")

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define f_in freopen("test.in","r",stdin);
#define f_out freopen("test.in","w",stdout);
#define debug(x) cerr << #x << " : " << x << "\n";
#define _ cin.sync_with_stdio(0); cin.tie(0);
#define tl cout <<"\nTime elapsed: "<<(1000 * clock() / CLOCKS_PER_SEC)<<"ms\n"


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

inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}

template<typename T = int>
inline T nxt(){
    char c=nc();T x=0; int f=1;
    for(;c>'9'||c<'0';c=nc())if(c=='-')f=-1;
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=nc()); x*=f;
    return x;
}

int main(){
    int n;
    cin >> n;
    cout << 0 << '\n';
    string s;
    cin >> s;
    if(s[0] == 'V') return 0;
    char c = s[0];
    int l = 0, r = n - 1;
    while(s[0] != 'V'){
        int mid = (l+r+1)/2;
        cout << mid << '\n';
        cin >> s;
        if(mid%2 == 0 && s[0] == c) l = mid;
        if(mid%2 == 1 && s[0] != c) l = mid;
        if(mid%2 == 0 && s[0] != c) r = mid;
        if(mid%2 == 1 && s[0] == c) r = mid;
    }
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
bool judge(int l,string S){
    int n = S.size();
    vector<string> s(n-l+1);
    for(int i = 0;i <= n-l;i++){
        s[i] = S.substr(i,l);
    }
    for(int i = 0;i <= n-l;i++){
        for(int j = i+l;j <= n-l;j++){
            if(s[i] == s[j])return true;
        }
    }
    return false;
}
int main(){
    int n;
    string S;
    cin >> n >> S;
    int r,l;
    r = n/2;
    l = 0;
    while(r-l > 1){
        if(judge((r+l)/2,S) == true){
            l = (r+l)/2;
        }else{
            r = (l+r)/2;
        }
    }
    if(judge(r,S) == true)cout << r << endl;
    else cout << l << endl;
    //cin >> n;
}


Measured memory_bytes: 6544
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static long MOD = 1000000007;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] s = br.readLine().split(" ");

        int n = Integer.parseInt(s[0]);
        int k = Integer.parseInt(s[1]);

        String[] s2 = br.readLine().split(" ");
        Integer[] nums = new Integer[n];
        List<Long> positives = new ArrayList<>();
        List<Long> negatives = new ArrayList<>();


        for (int i = 0; i < n; i++) {
            nums[i] = (Integer.parseInt(s2[i]));
            int temp = Integer.parseInt(s2[i]);
            if (temp<0)negatives.add((long) (temp));
            else  positives.add((long) temp);
        }

        boolean isPositive = false;

        int posCount = Math.min(k,positives.size());
        int negCount = k - posCount;

        if (negCount%2==0)isPositive = true;
        else{
            if(posCount-1>=0 && negCount+1<=negatives.size())isPositive=true;
        }

        if (isPositive){
            //positive sing = > select negatives or positives in groups of two (by whichever pair has higher product) and mul 1 more pos at the end if k nos not taken

            positives.sort(Collections.reverseOrder());
            Collections.sort(negatives);

            int negIdx = 0;
            int posIdx = 0;
            int total = k;
            long ans  = 1L;
            if(k%2==1){
                ans = positives.get(posIdx);
                ++posIdx;
                --total;
            }
            while (total>0){

                long negProd = negatives.size()-negIdx>=2 ? (negatives.get(negIdx)*negatives.get(negIdx+1)) : 0;
                long posProd = positives.size()-posIdx>=2 ? (positives.get(posIdx)*positives.get(posIdx+1)) : 0;


                ans = (ans * (Math.max(negProd,posProd)%MOD))%MOD;
                if(negProd>posProd)
                    negIdx += 2;
                else
                    posIdx += 2;
                total -= 2;
            }
            System.out.println(ans);
        }else{
            // sign will be negative, hence choose smallest k numbers(by abs value).
            Arrays.sort(nums, Comparator.comparingInt(Math::abs));
            long ans = 1L;
            for(int i = 0 ; i<k; i++){
                ans = (ans*nums[i])%MOD;
            }
            System.out.println((ans+MOD)%MOD);
        }

    }
}


Measured memory_bytes: 80124
#include <stdio.h>
int main(){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  for(int i=0;i<100;++i){
    c=c-b;
    if(c<1){
      printf("Yes");
      break;
    }
    a=a-d;
    if(a<1){
      printf("No");
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1732
n,m,x,y = gets.chomp.split(" ").map(&:to_i)
max_x=gets.chomp.split(" ").map(&:to_i).max
min_y=gets.chomp.split(" ").map(&:to_i).min
war="War"
if min_y-max_x>0 then
  for i in max_x+1..min_y do
    if x<i && i<y then
      war="No War"
    end
  end
end
puts war

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;


//System.out.println();
public class Main implements Runnable { //クラス名はMain

    public static void main(String[] args) {
    	Thread.setDefaultUncaughtExceptionHandler((t,e)->System.exit(1));
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
    }

    //1≤N≤10^5
    //1≤ai,bi,ci≤10^4
    //N
    //a1 b1 c1
    //a2 b2 c2
    //:
    //aN bN cN
    public void run() {
    	try {
	    	FastScanner0 sc = new FastScanner0(System.in);

	        int N = sc.nextInt();
	        int l[][] = new int[N][3];
	        int dp[][] = new int[N][3];

	        for (int i=0; i<N; i++) {
	        	l[i][0] = sc.nextInt();
	        	l[i][1] = sc.nextInt();
	        	l[i][2] = sc.nextInt();
	        }

	        //System.out.println("--------Start-----------");
	        MaxCalc maxcalc = new MaxCalc();

	        for(int i=0; i<N; i++) {
	        	if(i==0) {

	        		//
	        		dp[i] = l[i];
	        	}else {
	        		for(int k=0; k<3; k++) {
	        			MaxCalc val = maxcalc.max(dp[i-1],k);
	        			dp[i][k] = l[i][k] + val.max;
	        		}
	        	}
	        	//System.out.println(i + " ; dp : " +  Arrays.deepToString(dp));
	        }

	        System.out.println(Arrays.stream(dp[N-1]).max().getAsInt());


    	}catch(Exception e) {
    		e.printStackTrace();
    	}


    }
}

class MaxCalc {
	int i;
	int max = 0;
	public MaxCalc max(int[] nums,int ignore) {
		MaxCalc maxcalc = new MaxCalc();
        for (int i=0 ; i < nums.length; i++) {
            if (maxcalc.max < nums[i] && i != ignore) {
            	maxcalc.max = nums[i];
            	maxcalc.i = i;
            }
        }
        return maxcalc;
    }
}


//高速なScanner
class FastScanner0 {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner0(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


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

int main(){
    string S;
    cin >> S;
    bool e = false, w = false, s = false, n = false;

    for(int i = 0; i < S.length(); i++){
        char c = S[i];
        switch(c){
            case 'E': e = true; break;
            case 'W': w = true; break;
            case 'S': s = true; break;
            case 'N': n = true; break;
            default: break;
        }
    }
    if(e == w && n == s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}


//#########################################



int main() {
    ll a=LLD(),b=LLD(),x=LLD();
    if(a>0)
    cout<<(b/x)-((a-1)/x);
    else
        cout<<(b/x)+1;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,m;
int dp[1007][1007],a[1007][1007],sum[1007][1007],vis[1007][1007],total=0;
int solve(int x,int y){
	if(vis[x][y]) return dp[x][y];
	if(x==n && y==m) return 0;
	vis[x][y]=1;
	int turn=(x+y)%2,ret=0;
	if(turn==1){
		ret=-2e9;
		if(y!=m) ret=max(ret,solve(x,y+1));
		if(x!=n) ret=max(ret,solve(x+1,y)+sum[x+1][y]);
	}
	else{
		ret=2e9;
		if(y!=m) ret=min(ret,solve(x,y+1));
		if(x!=n) ret=min(ret,solve(x+1,y)+sum[x+1][y]);
	}
	dp[x][y]=ret;
	return ret;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>m>>n;
	for(int i=1;i<=n;i++){
		sum[i][0]=0;
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			sum[i][j]=sum[i][j-1]+a[i][j];
			total+=a[i][j];
		}
	}
	solve(0,0);
	//cout<<dp[0][0]<<endl;
	cout<<abs(total-2*dp[0][0])<<"\n";;
}



Measured memory_bytes: 19088
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 1e6;
char ss[maxN];
list<char> s; bool fliped = false;

int main()
{
  while (scanf(" %s", ss) != EOF)
  {
    s.clear(), fliped = false;
    for (int i = 0; ss[i]; i ++)
      s.push_back(ss[i]);

    int q; scanf("%d", &q);
    while (q --)
    {
      int op; scanf("%d", &op);
      if (op == 1)
        fliped = !fliped;
      else
      {
        int f; char c; scanf("%d %c", &f, &c);
        if (f == 1)
        {
          if (!fliped)
            s.push_front(c);
          else
            s.push_back(c);
        }
        else
        {
          if (!fliped)
            s.push_back(c);
          else
            s.push_front(c);
        }
      }
    }
    if (fliped)
      reverse(s.begin(), s.end());

    for (char c: s)
      printf("%c", c);
    printf("\n");
  }
  return 0;
}

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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n + 1), minimum_cost(n + 1);
    for(int i = 1; i <= n; i++)
        cin >> v[i];

    minimum_cost[1] = 0;
    for(int i = 2; i <= n; i++) {
        int curr_min_cost = INT_MAX;
        for(int j = 1; j <= k && i > j; j++)
            curr_min_cost = min(curr_min_cost, minimum_cost[i - j] + abs(v[i] - v[i - j]));
        minimum_cost[i] = curr_min_cost;
    }

    cout << minimum_cost[n];
    return 0;
}


Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

int main() {

	int n;
	std::cin >> n;
	std::vector<std::vector<int>> v(n);

	for (int i{}; i < n; ++i) {
		int u, k;
		std::cin >> u >> k;
		for (int j{}; j < k; ++j) {
			int t;
			std::cin >> t;
			v[u - 1].emplace_back(t - 1);
		}
	}


	std::vector<int> dist(n, 1<<25 );
	dist[0] = 0;
//	for (int i{0}; i < n; ++i) {
		std::queue<int> q;
		q.emplace(0);
		while (!q.empty()) {
			auto here = q.front(); q.pop();
			
			for (const auto&e : v[here]) {
				if (e!=0&&dist[e] > dist[here] + 1) {
					dist[e] = dist[here] + 1;
					q.emplace(e);
				}
			}

		}
	

	for (int i{}; i < n; ++i) {
		std::cout
			<< i + 1<< " "
			<<( dist[i] == (1 << 25) ? -1 : dist[i] )<< "\n";
	}

	return 0; 
}


Measured memory_bytes: 3148
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
using namespace std;

int n;
int ans = 0;

void dfs(long long x, int a, int b, int c) {
    if (n < x) return;
    if (a && b && c) ans++;
    dfs(10 * x + 3, 1, b, c);
    dfs(10 * x + 5, a, 1, c);
    dfs(10 * x + 7, a, b, 1);
    return;
}

int main()
{
    cin >> n;
    dfs(0, 0, 0, 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator>(const P& p) const {
        return ds != p.ds ? ds > p.ds : d > p.d;
    }
    int ds;
    array<int, 9> d;
};

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

    int b0[10] = { 0,2,5,5,4,5,6,3,7,6 };

    vector<int> a(m);
    for (int j = 0; j < m; j++) {
        cin >> a[j];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    //桁数を最大化する その中で、最大のAの個数を最大化する その中で、2番目のAの個数を最大化する
    //2番目以降のAだけで作れる消費マッチ棒数をDPで列挙 それで本当にいいのか？
    //単に、全部のAで作れる消費マッチ棒数をDPで列挙
    //最大のものを選び、いや、ちょうどNじゃないといけない
    //2番目以降のAだけで作れるN以下の消費マッチ棒数をDPで列挙 その消費マッチ棒数を作れる最大の桁数でDP
    //単に全部のAでいいか
    //dp[n]が桁数 大きいAから貪欲に取っていったらその桁数取れなくなったりしない？
    //構造体作った ところで、これも貪欲では いや、一番いいやつを保持して、一番いいやつを参照すればいいからいいのか

    vector<P> dp(n + 1);
    for (int i = 1; i <= n; i++) {
        dp[i].ds = -1;
    }
    for (int j = 0; j < m; j++) {
        int b = b0[a[j]];
        for (int i = b; i <= n; i++) {
            P p = dp[i - b];
            if (p.ds < 0) continue;
            p.ds++;
            p.d[j]++;
            if (p > dp[i]) dp[i] = p;
        }
    }

    P p = dp[n];
    string s(p.ds, '0');
    int d = 0;

    for (int j = 0; j < m; j++) {
        for (int i = 0; i < p.d[j]; i++) {
            s[d++] = '0' + a[j];
        }
    }
    if (d != p.ds) throw;

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main()
{
  int k;
  vector<vector<int>> servedTime(10, vector<int> (0));
  for (int i = 0; i < 5; i++) {
    int a;
    cin >> a;
    servedTime[a % 10].push_back(a);
  }

  int time = 0;
  int count = 1;
  for (int i = 0; i < servedTime[0].size(); i++) {
    time += servedTime[0][i];
    count++;
  }
  for (int i = 9; i >= 1; i--) {
    for (int j = 0; j < servedTime[i].size(); j++) {
      if (count != 5) {
        time += ((servedTime[i][j] / 10 + 1) * 10);
      } else {
        time += servedTime[i][j];
      }
       count++;
    }
  }
  
  cout << time << endl;
  
  return 0;
}

Measured memory_bytes: 256
import collections
n,x = map(int, raw_input().split(' '))
x-=1
mem = {}
def compute(n):
	if n in mem:
		return mem[n]
	if n == 0:
		return (1,1)
	else:
		h,p = compute(n-1)
		return (2*h + 3, 2*p + 1) 	
def iot(n,x,r,h):
	if h[0] > x: return
	if n == 0:
		h[0] += 1
		r[0] += 1
		return
	h[0] += 1
	if h[0] > x: return
	
	if h[0] + compute(n-1)[0] <= x:
		hh,pp = compute(n-1)
		h[0] += hh
		r[0] += pp
	else:
		iot(n-1, x, r, h)
	if h[0] > x: return
	
	h[0] += 1
	r[0] += 1

	if h[0] > x: return
	
	if h[0] + compute(n-1)[0] <= x:
		hh,pp = compute(n-1)
		h[0] += hh
		r[0] += pp
	else:
		iot(n-1, x, r, h)
	
	
	if h[0] > x: return
	
	h[0] +=1		
r,h = [0],[0]
iot(n,x,r,h)
print r[0]

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

int main(){
  string S;
  int judge = 0;

  cin >> S;
  for(int i = 0; i<3; i++){
    if(S[i]==S[i+1]){
      cout << "Bad" << endl;
      judge = 1;
      break;
    }
  }
  
  if(judge==0){
    cout << "Good" << endl;
  }
}

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

int main(){
    int N;
    cin >> N;
    int c[2 * N];
    vector<int> v;
    int sum = 0;

    for(int i = 0; i < 2 * N; i++){
        cin >> c[i];
        v.push_back(c[i]);
    }
    sort(v.begin(), v.end());

    for(int i = 0; i < v.size(); i += 2){
        sum += v[i];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VVI d;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,m;
  cin>>n>>m;
  d=VVI(n,VI(n));
  in a,b;
  forn(z,m){
    cin>>a>>b;
    --a;
    --b;
    d[a][b]=d[b][a]=1;
  }
  VI p;
  in sm=0;
  forn(i,n)
    p.PB(i);
  do{
    bool ok=1;
    forn(i,n-1)
      ok&=d[p[i]][p[i+1]];
    sm+=ok;
  }while(next_permutation(p.begin()+1,p.end()));
  cout<<sm<<endl;
  return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int N = 1000000;
  vi p;
  rep1 (i, N) {
    int temp = i * (i + 1) * (i + 2) / 6;
    if (temp > N) break;
    p.push_back(temp);
  }
  
  int m = p.size();
  vi dp0(N + 1, inf), dp1(N + 1, inf);
  dp0[0] = dp1[0] = 0;
  rep (i, N) {
    rep (j, m) {
      int i2 = i + p[j];
      if (i2 > N) break;
      chmin(dp0[i2], dp0[i] + 1);
      if (p[j] % 2 == 1) {
        chmin(dp1[i2], dp1[i] + 1);
      }
    }
  }

  
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;
    cout << dp0[n] << " " << dp1[n] << endl;
  }
}



Measured memory_bytes: 10484
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

int main(){
	int N;
	char s[1000000];
	cin >> N;
	scanf("%s", s);
	int etow = 0, wtoe = 0;
	for(int i = 0; i < N; ++i){
		if(s[i] == 'E') etow++;
	}
	long long int min = 9999999;
	for(int i = 0; i < N; ++i){
		if(s[i] == 'E') etow--; // not count itself as 'EtoW'
		if(etow+wtoe <= min) min = etow+wtoe;
		if(s[i] == 'W') wtoe++;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<string> a(n), b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];
	rep(i, n - m + 1)rep(j, n - m + 1) {
		bool flag = true;
		rep(k, m)rep(l, m) {
			if (a[i + k][j + l] != b[k][l]) flag = false;
		}
		if (flag) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

int main(void){
    ll R, C, K;
    cin >> R >> C >> K;
    vector<vector<ll>> V(R, vector<ll>(C, 0));
    for(int i = 0; i < K; i++){
        ll r, c, v;
        cin >> r >> c >> v;
        V[--r][--c] = v;
    }
    vector<vector<vector<ll>>> dp(R, vector<vector<ll>>(C, vector<ll>(4, 0)));
    for(int i = 0; i < R; i++){
        for(int j = 0; j < C; j++){
            for(int k = 3; k >= 0; k--){
                if(0 < i) dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]);
                if(0 < j) dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
                // if(0 < k) dp[i][j][k] = max(dp[i][j][k], dp[i][j][k - 1] + V[i][j]);
            }
            for(int k = 3; k >= 0; k--){
                // if(0 < i) dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]);
                // if(0 < j) dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
                if(0 < k) dp[i][j][k] = max(dp[i][j][k], dp[i][j][k - 1] + V[i][j]);
            }
        }
    }
    // for(int i = 0; i < R; i++){
    //     for(int j = 0; j < C; j++){
    //         for(int k = 0; k <= 3; k++){
    //             cout << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
    //         }
    //     }
    // }
    ll ans = 0;
    for(int k = 0; k <= 3; k++) ans = max(ans, dp[R - 1][C - 1][k]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 706088
#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>;

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

    vector<int> white(N + 1);
    rep(i, N) {
        white[i + 1] = white[i];
        if (S[i] == '.') ++white[i + 1];
    }

    int ans = N;
    rep(i, N) {
        int tmp = (i + 1 - white[i + 1]) + (white[N] - white[i + 1]);
        ans = min(ans, tmp);
    }

    cout << min({ans, white[N], N - white[N]}) << endl;
}

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

using namespace std;

int main()
{

    string S, T, temp;
    cin>>S>>T;
    int x= S.length();
    for(int i=0; i<x; i++)
    {
        temp=S;
        S[0]=S[x-1];
        for(int j=1; j<x; j++)
        {
            S[j]=temp[j-1];
        }
        if(S==T)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    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() {
	char x, y, op; vector<bool> vec(3);
	vec[0] = true; vec[1] = false; vec[2] = false;
	while (cin >> x >> op >> y) {
		if (x == 'A' && y == 'B') swap(vec[0], vec[1]);
		if (x == 'B' && y == 'A') swap(vec[1], vec[0]);
		if (x == 'A' && y == 'C') swap(vec[0], vec[2]);
		if (x == 'C' && y == 'A') swap(vec[2], vec[0]);
		if (x == 'B' && y == 'C') swap(vec[1], vec[2]);
		if (x == 'C' && y == 'B') swap(vec[2], vec[1]);
	}
	rep(i, 3) if (vec[i] == true) {
		switch (i) {
		case 0: cout << "A" << endl; break;
		case 1: cout << "B" << endl; break;
		case 2: cout << "C" << endl; break;
		}
		break;
	}
	return 0;
}


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

int main() {
  string S,T;
  cin>>S>>T;
  int64_t N=S.size(),M=T.size();
  vector<vector<int64_t>> p(26);
  for(int i=0;i<N;i++){
    int a=S[i]-'a';
    p[a].push_back(i);
  }
  vector<int> q(26);
  for(int i=0;i<26;i++){
    q[i]=p[i].size();
  }
  int64_t K=0,L=0;
  for(int i=0;i<M;i++){
    int a=T[i]-'a';
    if(q[a]==0){
      K=0,L=-1;
      break;
    }
    else{
      if(L>p[a][q[a]-1]){
        L=p[a][0];
        K++;
      }
      else{
        int b=lower_bound(p[a].begin(),p[a].end(),L)-p[a].begin();
        L=p[a][b];
      }
    }
    L++;
    if(L==N){
      K++;
      L=0;
    }
  }
  cout<<K*N+L<<endl;
}



Measured memory_bytes: 4652
package main

import (
  "fmt"
  "sort"
)

func main() {
  var n int 
  fmt.Scan(&n)
  a := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&a[i])
  }

  sort.Ints(a)
  sa := 0
  sb := 0
  for i := n - 1; i > -1; i -= 2 {
    sa += a[i]
  }
  for i := n - 2; i > -1; i -= 2 {
    sb += a[i]
  }
  fmt.Println(sa - sb)
}

Measured memory_bytes: 512
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
/*---------------------------------------------------------------------*/
const int N = 2e5+10;
const int INF = (int)1e9+5;
map<int,int>mp;
int main()
{
    _SAD()
    int a[4][4];
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];
            //mp[a]++;
        }
    }
    int n,m;
    cin>>n;
    char ch[4][4];
   // vector<int>v(n);
   mp.clear();
    rep(i,n)
    {
        cin>>m;
        mp[m]++;
    }
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(mp[a[i][j]]>0)
            {
               // cout<<"gu"<<nl;
                ch[i][j]='1';
            }
            else
            {
                ch[i][j]='0';
            }
        }
    }
   /* for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cout<<ch[i][j]<<" ";
        }
        cout<<nl;
    }*/
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(ch[i][j]=='1')
            {
                if((ch[i][j-1]=='1'&&ch[i][j+1]=='1')||(ch[i-1][j]=='1'&&ch[i+1][j]=='1')||(ch[i+1][j+1]=='1'&&ch[i-1][j-1]=='1')||(ch[i-1][j+1]=='1'&&ch[i+1][j-1]=='1'))
                {
                    cout<<"Yes"<<nl;return 0;
                }
            }
        }
    }
    cout<<"No"<<nl;
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <iostream>
#include <algorithm>

#define int long long

using namespace std;

const int N = 2e5 + 10;

int r[N];

int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    r[0] = s[0] - '0';
    int ten = 10;
    int mod = 2019;
    int ans = 0;
    map<int, int> m;
    for (int i = 1; i < s.length(); ++i)
    {
        r[i] = ((s[i] - '0') * ten + r[i - 1]) % mod;
        ten *= 10;
        ten %= mod;
    }
    for (int i = s.length() - 1; i >= 0; --i)
    {
        ans += m[r[i]];
        ++m[r[i]];
    }
    cout << ans + m[0];
    return 0;
}


Measured memory_bytes: 5348
import copy

n = int(input())
array = [int(x) for x in input().split()]
nn = int(input())
res = []
for i in range(nn):
    aarraayy = copy.copy(array)
    x, y = map(int, input().split())
    aarraayy[x-1] = y
    res.append(sum(aarraayy))

for j in res:
    print(j)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

template <class T>
struct BIT{
  int n;
  vector<T> bit; //[1,N]

  BIT(int _n){
    n = _n + 1;
    bit.resize(n,0);
  }

  T sum(int i){
    T sum = 0;
    while(i > 0){
      sum += bit[i];
      i -= i & -i;
    }
    return sum;
  }

  void add(int i,T x){
    while(i < n){
      bit[i] += x;
      i += i & -i;
    }
  }

  int lower_bound(T x) {
    int left = -1, right = n;
    while(right - left > 1) {
      int mid = (left + right)/2;
      if(sum(mid) >= x) right = mid;
      else left = mid;
    }
    return right;
  }
};

template<class T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}

signed main(){

  int q; cin >> q;
  vector<int> num(q),as,bs;
  for(int i = 0; i < q; i++){
    cin >> num[i];
    if(num[i] == 1){
      int a,b; cin >> a >> b;
      as.push_back(a);
      bs.push_back(b);
    }
  }
  vector<int> v = compress(as);
  map<int,int> mp;
  for(int i = 0; i < v.size(); i++){
    mp[v[i]] = i+1;
  }

  BIT<int> bit1(v.size()); //値
  BIT<int> bit2(v.size()); //indexの数
  int cnt = 0,add = 0;
  for(int i = 0; i < q; i++){
    if(num[i] == 1){
      bit1.add(mp[as[cnt]],as[cnt]);
      bit2.add(mp[as[cnt]],1);
      add += bs[cnt];
      cnt++;
    }
    else {
      int idx = bit2.lower_bound((cnt+1)/2);
      int x = v[idx-1];
      int ans = 0;
      ans += x * bit2.sum(idx-1) - bit1.sum(idx-1);
      ans += -x * (bit2.sum(v.size()) - bit2.sum(idx)) + (bit1.sum(v.size()) - bit1.sum(idx));
      cout << x << " " << ans + add << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 14316
#include<iostream>
using namespace std;
int main(){
  int n,x,t;
  cin>>n>>x>>t;
  if(n%x==0){
    int p=n/x;
    cout<<p*t;}
  else{
    int k=n/x;
    k++;
    cout<<k*t;}
  return 0;
}


Measured memory_bytes: 3556
N,M,Q=map(int,input().split())
MAP=[[0]*(N+1) for i in range(N+1)]
for i in range(M):
    l,r=map(int,input().split())
    l-=1
    r-=1
    MAP[0][r]+=1
    MAP[0][N]-=1
    MAP[l+1][r]-=1
    MAP[l+1][N]+=1
ans=[[0]*(N+1) for i in range(N+1)]
ans[0][0]=MAP[0][0]
for y in range(1,N+1):
    ans[0][y]=ans[0][y-1]+MAP[0][y]
for x in range(1,N+1):
    ans[x][0]=ans[x-1][0]+MAP[x][0]
    for y in range(1,N+1):
        ans[x][y]=ans[x-1][y]+ans[x][y-1]-ans[x-1][y-1]+MAP[x][y]
for i in range(Q):
    p,q=map(int,input().split())
    print(ans[p-1][q-1])

Measured memory_bytes: 11392
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

//わけわかめ
int P[100001];
bool dame[100001];
int Find(int A) {
	if (P[A] < 0) return A << 1;
	return P[A] = Find(P[A] >> 1) ^ (P[A] & 1);
}

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


	int N = getint(), M = getint();
	rep1(i, N) P[i] = -1;
	rep(i, M) {
		int a = Find(getint());
		int b = Find(getint());

		//なんてセンスのない
		int a1 = a >> 1;
		int b1 = b >> 1;
		if (a1 == b1) {
			if (!((a ^ b) & 1)) dame[a1] = true;
			continue;
		}
		if (P[a1] > P[b1]) {
			P[b1] += P[a1];
			dame[b1] |= dame[a1];
			P[a1] = b ^ !(a & 1);
		}
		else {
			P[a1] += P[b1];
			dame[a1] |= dame[b1];
			P[b1] = a ^ !(b & 1);
		}
	}

	ll x = 0, y = 0, z = 0;
	rep1(i, N) {
		if (P[i] < 0) {
			if (P[i] == -1) z++;
			else if (dame[i]) y++;
			else x++;
		}
	}
	printf("%lld\n", x * x + (x + y) * (x + y) + 2 * N * z - z * z);

	Would you please return 0;
}

Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main() {
    int n, b, f, r, v;
    cin >> n;
    int a[4][3][10] = {};
    for (int i=0; i < n; i++) {
        cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1] += v;
    }
    for (int j=0; j < 4; j++){
        for (int k=0; k < 3; k++) {
            for (int l=0; l < 10; l++) {
                cout << " " << a[j][k][l]; 
            }
            cout << endl;
        }
        if (j<=2) {
            for (int c=0; c<20; c++){
                cout << "#"; 
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char C;
  cin >> C;
 
  string alpha="abcdefghijklmnopqrstuvwxyz";
  
  for(int i=0; i<26; i++){
  if(alpha[i]==C){
    cout << alpha[i+1] << endl;
    break;
  }
  }
  
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	long long n;
	long long sum = 0;
	vector<long long> a;
	cin >> n;

	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.pb(t);
		sum += t;
	}
	long long m = (long long)n * (n+1) / 2;
	if(sum % m != 0){
		puts("NO");
		return 0;
	}
	long long k = sum / m;

	vector<long long> b;
	b.push_back(a[n-1] - a[0]);
	for(int i=1; i<n; i++){
		b.push_back(a[i-1] - a[i]);
	}
	bool f = true;
	for(int i=0; i<n; i++){
		b[i] += k;
		//printf("%d ", b[i]);
		if(b[i] < 0 || b[i] % n != 0) {
			f = false;
			break;
		}
	}
	if(f) puts("YES");
	else puts("NO");
	
	return 0;
}


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

using namespace std;

int cnt[27];
int one = 0, two = 0;
char buf[210];
bool cmp(int a, int b){return a>b;}

bool check(){
	for(int i=0;i<26;i++){
		cnt[i] %= 4;
		if(cnt[i] % 2 == 1){
			if(one == 0) return false;
			else one--, cnt[i]--;
		}
		if(cnt[i] == 2){
			if(two == 0) return false;
			else two--, cnt[i]-=2;
		}
	}
	return true;
}
int main(){
	int H,W;
	cin >> H >> W;
	for(int i=0;i<H;i++){
		scanf("%s", buf);
		for(int j=0;j<W;j++){
			cnt[buf[j] - 'a'] ++;
		}
	}
	if(H % 2 == 1 && W % 2 == 1) one = 1;
	if(H % 2 == 1) two += W/2;
	if(W % 2 == 1) two += H/2;
	if(check()) puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
from collections import Counter
 
N = int(input())
a = Counter(map(int, input().split()))
Q = int(input())
 
sum_a = sum(a.elements())
 
for i in range(Q):
    b, c = map(int, input().split())
    a[c] += a[b]
    sum_a += (c-b) * a[b]
    a[b] = 0
    print(sum_a)

Measured memory_bytes: 22056
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,K; cin>>N>>K;
  int X,Z; cin>>X;
  Z=X;
  rep(i,1,N){
    int Y; cin>>Y;
    X=__gcd(X,Y);
    Z=max(Z,Y);
  }
  string ans="IMPOSSIBLE";
  if(K%X==0&&Z>=K) ans="POSSIBLE";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256