akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;

//Aはソートする配列,jは交換する位置(j とj-1を入れ替える)
int* swap(int* A,int j){
    int tmp  = A[j];
    A[j] = A[j-1];
    A[j-1] = tmp;
    return A;
}




int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int A[N]; //ソートする配列
    int swapCount = 0;

    REP(i,N){
        cin >> A[i];
    }

    bool sortDoing = true;

    for(int i = 0;sortDoing;i++){
        sortDoing=false;
        for(int j = N-1; j >= i+1; --j){
            if(A[j] < A[j-1]){
                swap(A,j);
                swapCount++;
                sortDoing = true;
            }
        }
    }

    REP(i,N){
        if(i == N-1){
        cout << A[i] << endl;
        break;
        }
        cout << A[i] << " ";
    }
    cout << swapCount << endl;
    

    return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int mx = max({a, b, c});
    int d = 3 * mx - a - b - c;

    if (d % 2 == 0) cout << d / 2 << endl;
    else cout << d / 2 + 2 << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

class dice{
    int label2num[7];
    map<int,int> num2label;
    public:
    dice(int a[6]){
        for(int i=0;i<6;i++) label2num[i+1]=a[i];
        for(int i=0;i<6;i++) num2label[a[i]]=num2label[a[i]]*10+(i+1);
    }
    int getNum(int label){
        return label2num[label];
    }
    vector<int> getLabels(int num){
        vector<int> r(0);
        for(int l=num2label[num];l>0;l/=10){
            r.push_back(l%10);
        }

        return r;
    }
    vector<int> getSideNums(int topLabel){
        vector<int> r(4);
        int *s;
        switch(topLabel){
            case 1:
                s=new int[4]{2,3,5,4};
                break;
            case 2:
                s=new int[4]{1,4,6,3};
                break;
            case 3:
                s=new int[4]{1,2,6,5};
                break;
            case 4:
                s=new int[4]{1,5,6,2};
                break;
            case 5:
                s=new int[4]{1,3,6,4};
                break;
            case 6:
                s=new int[4]{2,4,5,3};
                break;
        }
        for(int i=0;i<4;i++) r[i]=label2num[s[i]];

        delete[] s;
        return r;
    }
};

bool isSame(int a[6], int b[6]){
    dice A(a), B(b);

    int atop=1;
    vector<int> btops=B.getLabels(A.getNum(1));

    for(int btop : btops){
        if(A.getNum(7-atop) != B.getNum(7-btop)) continue;

        vector<int> asides=A.getSideNums(atop), bsides=B.getSideNums(btop);
        for(int i=0;i<4;i++){
            bool flg=true;
            for(int j=0;j<4;j++) flg=flg && (asides[j]==bsides[(j+i)%4]);
            if(flg){
                return true;
            }
        }
    }
    return false;
}

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

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

    for(int p=0;p<n;p++){
        for(int q=p+1;q<n;q++){
            if(isSame(a[p],a[q])){
                cout << "No" << endl;
                return 0;
            }
        }
    }

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


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

using namespace std;

const int maxN = 1e5 + 10;
int dp[maxN];
int h[maxN];
int n, k;

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

	for (int i = 1; i < n; ++i)
	{
		dp[i] = static_cast<int>(1e9 + 10);
	}
	dp[0] = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 1; j <= k && i + j < n; ++j)
		{
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
		}
	}
	cout << dp[n - 1];
	return 0;
}

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

int main() {
  double N, K;
  cin >> N >> K;
  double a = 1/N;
  double p = 0;
  for (int i = 1; i <= N; i++) {
    int w = i;
    double x = a;
    while (w < K) {
      x /= 2;
      w *= 2;
    }
    p += x;
  }
  cout << fixed << setprecision(12) << p << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

ll n, T;
ll t[200005];

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

    ll ans = T;
    for (int i = 0; i < n-1; i++) {
       if (t[i+1] - t[i] <= T) {
           ans += t[i+1] - t[i];
       } else {
           ans += T;
       }
    }

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
#define PN() {cout << "No" << endl; return 0;}
#define PY() {cout << "Yes" << endl; return 0;}

int main(){
  long long int h,w; cin >> h >> w;
  vector<pair<long long int,int>> a(h+w);
  for(int i=0;i<h;i++){
  	int t;
    cin >> t;
    a[i].first = t; a[i].second = 0;
  }
  for(int i=h;i<h+w;i++){
  	int t;
    cin >> t;
    a[i].first = t; a[i].second = 1;
  }
  sort(a.begin(), a.end());
  long long int ans = 0;
  h++; w++;
  for(auto x: a){
  	int wa = x.first;
    if(x.second == 0){ans = ans + w*wa; h--;}
    else if(x.second == 1){ans = ans + h*wa; w--;}
    if(h==1 && w==1) break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
int main(){
  std::string str,ans;
  std::cin>>str;
  ans="Good";
  for (int i = 0; i < 3; ++i) {
    if (str[i]==str[i+1]){
      i=3;
      ans="Bad";
    }
  }
  std::cout<<ans<<"\n";
}


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

a_set=set()

for index in range(m):
    a_set.add(int(input()))

ans_list=[]

for index in range(n + 1):
    ans_list.append(0)

for index in range(n + 1):
    if index == 0:
        ans_list[index] += 1
        continue
    if index == 1 and (index not in a_set):
        ans_list[index] += ans_list[index - 1]
        continue
    
    if index not in a_set:
        if (index - 1) not in a_set:
            ans_list[index] += ans_list[index - 1]
            ans_list[index] %= 1000000007
        if (index - 2) not in a_set:
            ans_list[index] += ans_list[index - 2]
            ans_list[index] %= 1000000007

print(ans_list[n])


Measured memory_bytes: 11884
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <__msvc_all_public_headers.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
 
typedef long long  ll;

#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<"\n"; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define halt {cout<<"NO"; return 0;}

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int N = 5010;
const int INF = 1e8;
const ll LL_INF=1e18;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
int divide(int a, int b)
{
          return (a+b-1)/b;
}
int main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int questions=1;
 // cin>>questions;
 while(questions--)
 {
        string s;
        int n=3;
        cin>>s;
        if(s=="RRR") cout<<3;
        else if(s=="RRS") cout<<2;
        else if(s=="SRR") cout<<2;
        else if(s=="SSS") cout<<0;
        else cout<<1;
         
 }
 
 
 
 
 // !!! LOOK AT NUMBER OF QUESTIONS IN A PROBLEM !!! (cin>>questions)
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int col, row;
  cin >> col >> row;
  char img[col + 2][row + 2];
  string cols[col];
  for(int i = 0; i < col; i++)
    cin >> cols[i];
  for(int i = 0; i < col + 2; i++){
    for(int j = 0; j < row + 2; j++)
      if(i == 0 || i == col + 1){
        cout << '#';
      }else if(j == 0 || j == row + 1){
        cout << '#';
      }else{
        cout << cols[i - 1][j - 1];
      }
    cout << endl;
  }
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,M;
  cin >> N >> M;

  if(M == 1){
    cout << 0 << endl;
    return 0;
  }
  if( N >= M){
    cout << 0 << endl;
    return 0;
  }

  vector<ll> v(M);
  for(int i = 0; i < M; i++){
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());

  vector<ll> w(M-1);
  for(int i = 0; i < M-1; i++){
    w[i] = v[i+1] - v[i];
  }

  sort(w.rbegin(), w.rend());

  ll ans = v[v.size()-1] - v[0];

  for(int i = 0; i < N-1; i++){
    ans -= w[i];
  }

  cout << ans << endl;

}


Measured memory_bytes: 1792
using System;

namespace AtCorderBeginnerContest121 {
    class B {
        static void Main(string[] args) {
            string[] vals = Console.ReadLine().Split(' ');
            int N = int.Parse(vals[0]),
                M = int.Parse(vals[1]),
                C = int.Parse(vals[2]);

            int[] B = new int[M];

            vals = Console.ReadLine().Split(' ');
            for (int i = 0; i < 20 && i < M; i++) {
                B[i] = int.Parse(vals[i]);
            }

            int ans;
            int count = 0;
            for (int i = 0; i < 20 && i < N; i++) {
                vals = Console.ReadLine().Split(' ');
                ans = C;
                for (int j = 0; j < 20 && j < M; j++) {
                    ans += int.Parse(vals[j]) * B[j];
                }
                if (ans > 0) {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  //ll n;
  //cin >> n;
  ll a, b, c,d;
  cin >> a >> b>>c>>d;
  //string s; cin >> s;
  ll result = 0;
  bool judge = true;
  cout<<min(a,b)+min(c,d)<<endl;

  /*
  vector<ll> a(n);
  for(i=0;i<n;i++)
    cin >> a[i];
  //for(i=0;<n;i++)
  */





  return 0;
}

Measured memory_bytes: 256
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 1005;
int d[N][N];
int ox[] = {0,0,1,-1};
int oy[] = {1,-1,0,0};
char a[N][N];
int n,m,ch,cw,dh,dw;
#define sp pair< int, pr> 
bool ok(int x,int y){
    return (x >= 1 && x <=n && y >= 1 && y <= m && a[x][y] != '#');
}
int shortestPath(){
    if (!ok(ch,cw)) return -1;
    priority_queue< sp, vector<sp>, greater<sp> > pq;
    up(i,1,n) up(j,1,m) d[i][j] = INT_MAX;
    d[ch][cw] = 0;
    pq.push({0, {ch,cw}});
    while (pq.size()){
        pr u = pq.top().second;
        int value = pq.top().first; 
        pq.pop();
        #define x u.first
        #define y u.second
        if (value != d[x][y]) continue;
        // cout << value << ' ' << x << ' ' << y << '\n';
        if (x == dh && y == dw) return value;
        for (int i=0;i<4;++i){
            int nx = x + ox[i], ny = y + oy[i];
            if (!ok(nx,ny)) continue;
            if (d[nx][ny] > d[x][y]) {
                d[nx][ny] = d[x][y];
                pq.push({d[x][y], {nx, ny}});
            }
        }
        for(int xAdd = -2;xAdd <= 2; ++xAdd){
            for(int yAdd = -2; yAdd <= 2; ++yAdd){
                if (xAdd == 0 && yAdd == 0) continue;
                int nx = x + xAdd, ny = y + yAdd;
                if (!ok(nx,ny)) continue;
                if (d[nx][ny] > d[x][y] + 1) {
                    d[nx][ny] = d[x][y] + 1;
                    pq.push({d[x][y] + 1, {nx, ny}});
                }
            }
        }
    }
    return -1;

}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    cin >> ch >> cw >> dh >> dw;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j) cin >> a[i][j];
    }
    cout << shortestPath();
}

Measured memory_bytes: 8700
def func2(input_list):
    if n >= m:
        return 0

    input_list.sort()

    input_diff = []
    for i in range(m-1):
        diff = input_list[i+1] - input_list[i]
        input_diff.append(abs(diff))

    input_diff.sort(reverse=True)
    ans = input_list[-1] - input_list[0]
    for i in range(0, n-1):
        ans -= input_diff[i]

    return ans

n, m = map(int, input().split())
input_list = [int(i) for i in input().split()]

print(func2(input_list))

Measured memory_bytes: 13840
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){

  int a, b, c, x;

  cin>>a>>b>>c>>x;

  int cnt=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(i*500+j*100+k*50==x) cnt++;
      }
    }
  }

  cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<stack>

#define LL long long


using namespace std;

const int maxa=2010;
const int maxn=2000100;
const int mod=1e9+7;
const int maxc=40010;
LL ans;
int n;
int a[maxn];
int b[maxn];
int ma[maxa*2][maxa*2];
LL f[maxa*2][maxa*2];
LL fac[maxc], inv[maxc];

LL power_mod(LL p, LL q) {
    LL ret = 1;
    while (q) {
        if (q & 1) ret = ret * p % mod;
        p = p * p % mod;
        q >>= 1;
    }
    return ret;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i <= maxc - 10; ++i) fac[i] = fac[i - 1] * i % mod;
    inv[maxc - 10] = power_mod(fac[maxc - 10], mod - 2);
    for (int i = maxc - 11; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
}

LL C(int x, int y) {
    return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main(){
    //freopen("P2742_8.in","r",stdin);

    int maxa=0;
    int maxb=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int p,q;
        scanf("%d%d",&p,&q);
        a[i]=p;
        b[i]=q;
        ma[p][q]++;
        if (p>maxa) maxa=p;
        if (q>maxb) maxb=q;
    }
    init();
    for(int i=1;i<=2*maxa+1;i++){
        for(int j=1;j<=2*maxb+1;j++){
            f[i][j]=(f[i-1][j]+f[i][j-1])%mod;
            if (maxa+1-i>=0 && maxb+1-j>=0){
                f[i][j]+=ma[maxa+1-i][maxb+1-j];
                f[i][j]%=mod;
            }
        }
    }
    LL ans=0;
    for(int i=1;i<=n;i++){
        int p,q;
        p=a[i]+maxa+1;
        q=b[i]+maxb+1;
        ans=(ans+f[p][q])%mod;
    }
    for (int i=1;i<=n;i++){
        ans=(ans-C(a[i]+a[i]+b[i]+b[i],a[i]+a[i])+mod) % mod;
    }
    printf("%lld",ans * power_mod(2, mod - 2) % mod);
    //fclose(stdin);

}






Measured memory_bytes: 166144
a_point, b_point, c_point, possible_of_distance = map(int, input().split())

a_b_distance = abs(a_point - b_point)
a_c_distance = abs(a_point - c_point)
b_c_distance = abs(b_point - c_point)

if a_c_distance <= possible_of_distance:
    print('Yes')
elif max(a_b_distance, b_c_distance) <= possible_of_distance:
    print('Yes')
elif a_c_distance == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9120
import java.util.Scanner;
import java.util.Stack;

/**
 * AIZU ONLINE JUDGE 507
 */

public class Main {
	private int n;
	private Stack<Integer> state;
	
	private Main() {
		Scanner in = new Scanner(System.in);
		while(true) {
			this.n = in.nextInt();
			if(n==0) break;
			state = new Stack<Integer>();
			backtrack(n, state);
		}
	}
	
	private boolean check(Stack<Integer> state, int value) {
		int sum = 0;
		for(int i:state) {
			sum += i;
		}
		if(sum+value > this.n){
			return false;
		} else {
			return true;
		}
	}
	
	private void backtrack(int n, Stack<Integer> state) {
		int sum = 0;
		for(int i:state) {
			sum += i;
		}
		if(sum == this.n){
			StringBuilder stream = new StringBuilder("");
			for(int i:state) {
				stream.append(i+" ");
			}
			System.out.println(stream.toString().trim());
			return;
		}
		for(int i = this.n;i>0;i--) {
			if((!state.empty()) && (state.peek() < i)) {
				// 最右の列がのその左側の列より少なくなる場合
			}else if(check(state,i)) {
				state.push(i);
				backtrack(i-1,state);
				state.pop();
			}
		}
		return;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new Main();
	}

}

Measured memory_bytes: 12000
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;

using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int n;
	int max = 0;
	int min = 1000000000;
	cin >> n;
	vector<int> a(n);
	fi(n) {
		cin >> a[i];
		if (a[i] > max) {
			max = a[i];
		}
		if (a[i] < min) {
			min = a[i];
		}
	}
	ce(max - min);
	
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

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

//#include <fstream>
int main(void)
{
	string currStr;
	string strMostFrequenty;
	string strLongest;
	map<string, int> strCount;

	//ifstream ifs("data.txt");
	istream& in=cin;

	while(!in.eof())
	{
		in >> currStr;
		if(currStr.length() > strLongest.length())
			strLongest=currStr;

		if(strCount.count(currStr)==1)
		{
			strCount[currStr]++;
			if(strCount[currStr] > strCount[strMostFrequenty])
				strMostFrequenty=currStr;
		}
		else
			strCount.insert(map<string, int>::value_type(currStr, 1));
	}

	cout << strMostFrequenty << ' ' << strLongest << endl;
	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 105
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,st[M],ed[M],ans;
bool vis[M];
priority_queue<int,vector<int>,greater<int>> q;
int main()
{
	RI(n);
	ans = 0;
	REP(i,1,n)
	{
		RI(st[i], ed[i]);
		REP(j,st[i],ed[i]) if(!vis[j])
		{
			vis[j] = true;
			ans += 50;
		}
	}

	REP(i,1,31)
	{
		REP(j,1,n) if(st[j]==i) q.push(ed[j]);
		while(!q.empty() && q.top()<i) q.pop();
		if(!q.empty())
		{
			q.pop();
			ans += 50;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
typedef long long ll; 
#define pb push_back
#define mp make_pair
#define mod 998244353
#define vi vector <ll>
using namespace std ; 
ll power(ll x,ll y,ll m)
{            //power(x,y)=x^y  %m;
	ll res=1%m;
	while(y)
	{
	    if(y&1)
	    res=(res*x)%m;
	    x=(x*x)%m;
	    y=(y>>1)%m;
	}
	return res;
}
ll mod_inverse(ll x,ll m)
{
	return power(x,m-2,m);
}
ll n;
ll func(vector<pair<ll,ll> > pp)
{
    sort(pp.rbegin(),pp.rend());
     set<ll> st;
     ll res=0;
    for (ll i = 0; i < n; i++) {
        st.insert(i);
    }
    for (ll i=0;i<(ll)pp.size();i++) 
    {
        auto it = st.lower_bound(pp[i].second);
        if (it == st.begin()) 
        {
            continue;
        }
        --it;
        st.erase(it);
        res += pp[i].first;
    }
    return res;
}
int main ()
{
    ios_base :: sync_with_stdio ( false );
    cin.tie( NULL );
    cout.tie( NULL );
ll t = 1 ;
cin>>t;
while ( t--)  
{
  //ll n;
  cin>>n;
  ll ans=0;
  vector<pair<ll,ll>  >v;
  vector<pair<ll,ll>  >v1;
  for(ll i=0;i<n;i++)
  {
      ll k,l,r;
      cin>>k>>l>>r;
      if(l>r)
      {ans+=r;
      v.pb(mp(l-r,k));
      }
      else
      {ans+=l;
      v1.pb(mp(r-l,n-k));
      }
      
  }
 
ans+=func(v);
ans+=func(v1);
cout<<ans<<"\n";
}
 

 return 0;
}


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

int main() {
  long K, N, maxi, max, i;
  cin >> K >> N;

  long A[N];
  for (i = 0; i < N; i++) {
    cin >> A[i];
  }
  max = 0;
  for (i = 0; i < N; i++) {
    if (i == N - 1) {
      if (K - A[N - 1] + A[0] > max) {
        max = K - A[N - 1] + A[0];
        maxi = N - 1;
      }
    } else {
      if (A[i + 1] - A[i] > max) {
        max = A[i + 1] - A[i];
        maxi = i;
      }
    }
    }
  cout << K - max << endl;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i ,n) cin >> a[i];
    int m; cin >> m;
    vector<int> b(m);
    rep(i ,m) cin >> b[i];
    vector<int> result;
    set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(result,result.end()));
    for(auto x : result){
        cout << x << endl;
    }
}


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

void print_row(vector<int> A) {
  for (int i = 0; i < A.size(); i++) {
    cout << A.at(i);
    if (i < A.size() - 1) {
      cout << " ";
    }
    else {
      cout << endl;
    }
  }
}

int main() {
  // Input
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  // Compute
  int cnt = 0;
  int flag = 1;
  while (flag == 1) {
    flag = 0;
    for (int j = N-1; j > 0; j--) {
      if (A.at(j-1) > A.at(j)) {
        int temp = A.at(j-1);
        A.at(j-1) = A.at(j);
        A.at(j) = temp;
        flag = 1;
        cnt++;
      }
    }
  }
  
  // Output
  print_row(A);
  cout << cnt << endl;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
typedef long long ll;
#define FOR(i,n) for(int i=0;i<n;i++)

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

  int c=0,ans=0;
  for(int i=0;i<n-1;i++){
    if(a[i] >= a[i+1])c++;
    else c=0;

    ans = max(ans,c);
  }
  cout <<ans;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

#define MAX_V 300
#define INF 1000000000000000
struct edge{int to, cost;};
int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s, int t){
    priority_queue<Pii, vector<Pii>, greater<Pii>> que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(Pii(0, s));

    while(!que.empty()){
        Pii p = que.top(); que.pop();
        int v = p.second;
        if(v == t) return;
        if(d[v] < p.first) continue;
        REP(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(Pii(d[e.to], e.to));
            }
        }
    }
}

void add_edge(int from, int to, int cost){
    G[from].push_back(edge({to, cost}));
}


signed main(){

    int N;
    cin >> N;
    vector< pair<int, vector<int> > > A;
    int a;
    REP(i, N){
        REP(j, N){
            cin >> a;
            if(i < j){
                A.push_back(pair<int, vector<int> >(a, vector<int>({i, j})));
            }
        }
    }
    SORT(A);

    V = N;

    int ans = 0;
    REP(i, A.size()){
        int c = A[i].first;
        int s = A[i].second[0];
        int t = A[i].second[1];

        dijkstra(s, t);
        if(d[t] < c){
            cout << -1;
            return 0;
        }else if(d[t] > c){
            add_edge(s, t, c);
            add_edge(t, s, c);
            ans += c;
        }
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
string a[105];
int main()
{
	int n,i;
    scanf("%d %*d",&n);
    for(i = 0;i < n;i++) cin >> a[i];
    sort(a,a + n);
    for(i = 0;i < n;i++) cout << a[i];
    return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
 
l = [A, B, C, D, E]
d = []
 
for i in l:
    if i % 10 == 0:
        d.append(0)
    else: 
        d.append(10 - (i % 10))
 
print(sum(l) + sum(d) - max(d)) 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int a, b, c, d;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a >> b >> c >> d;
	cout << max(a*b, c*d) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
template <typename T = int>
T in() {
    T temp; cin >> temp; return temp;
}

template <typename VType = int>
list<VType> const LR(VType start, VType end) {
    list<VType> ret; for (VType i = start; i < end; i++) ret.push_back(i); return move(ret);
}

int GoRight(int& i, int n, int* h) {
    int count = 0;
    for (; i < (n - 1); i++) {
        if (h[i + 1] > h[i]) break;
        count++;
    }
    return count;
}

int main() {
   int N;
   cin >> N;
   int H[N];
   for (int i = 0; i < N;i++) cin >> H[i];

   int max_count = 0;
   for (int i = 0; i < N - 1; i++) {
        int temp = GoRight(i, N, H);
        if (max_count < temp) max_count = temp;
   }

   cout << max_count << endl;
   return 0;
}




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

int main(){
    
    int x;
    int a,b,c;
    
    cin >> a >> b >>c;  
    if(b < a){
        x = a;
        a = b;
        b = x;
    }
    if(c < a){
        x = a;
        a = c;
        c = x;
        x = b;
        b = c;
        c = x;
        cout << a << " " << b << " " << c << endl;
        return 0;
    }
    if(b > c){
        x = c;
        c = b;
        b = x;
    }
    
    cout << a << " " << b << " " << c << endl;
    
    return 0;
}

Measured memory_bytes: 1164
s = input() + 'x'
x = []
cnt = 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        cnt += 1
    else:
        x.append(cnt)
        cnt = 1
for i in range(len(x) // 2):
    print('0 ' * (x[i * 2] - 1), end='')
    print((x[i * 2] + 1) // 2 + x[i * 2 + 1] // 2,
          x[i * 2] // 2 + (x[i * 2 + 1] + 1) // 2,
          end=' ')
    print('0 ' * (x[i * 2 + 1] - 1), end='')
print()


Measured memory_bytes: 5484
#include<iostream>
#include<cmath>
#define int long long
using namespace std;
int n, p;
int pow2(int x, int y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y%2 == 0) 
        return pow2(x, y/2)*pow2(x, y/2); 
    else
        return x*pow2(x, y/2)*pow2(x, y/2); 
}
signed main()
{
	cin >> n >> p;
	if(n==1)
	{
		cout << p;
		return 0;
	}
	if(n>40)
	{
		cout << 1;
		return 0;
	}
	int ans=1;
	int lim=sqrt(p);
	for(int i = 1; i <= lim; i++)
	{
		if(pow2(i, n)>p)	break;
		if(p%pow2(i, n)==0) ans=i;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long n,t;
    cin >> n>>t;
    vector<long long> T(n);
    for (long long i = 0; i < n;i++){
        cin >> T[i];
    }
    long long sum = 0;
    for(int i = 0;i<n-1;i++){
        if(T[i+1]-T[i]<t){
            sum +=T[i+1]-T[i];
        }else{
            sum+=t;

        }
    }

    cout << sum+t<<endl;

}

Measured memory_bytes: 1792
import sys
dataset = sys.stdin.readlines()
 
 
def gcd(a, b):
    if b > a: return gcd(b, a)
    if a % b == 0: return b
    return gcd(b, a % b)
 
def lcd(a, b):
    return a * b // gcd(a, b)
 
for item in dataset:
    a, b = list(map(int, item.split()))
    print(gcd(a, b), lcd(a,b))

Measured memory_bytes: 7700
#include <bits/stdc++.h>
#define mx 20000
using namespace std;
typedef long long ll;
ll k, s, ans;

int main()
{
	cin >> k >> s;
	for(int x = 0; x <= k; x++)
	{
		for(int y = 0; y <= k; y++)
		{
			ll z = s - (x + y);
			if(z >= 0 && z <= k)
			{
				ans++;
			}
		}
	}

	cout << ans;
}

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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,T,L,Now;

int Ans[maxn];

void Work(){
//	cout<<Now<<endl;
	Now=(Now%n+n)%n;
	sort(Ans,Ans+n);
	rotate(Ans,Ans+Now,Ans+n);
	REP(i,0,n-1)printf("%d\n",Ans[i]);
}

void Init(){
	read(n,L,T);
	REP(i,0,n-1){
		int a,w;
		read(a,w);
		if(w==1)Ans[i]=(a+T)%L;else Ans[i]=(a-T%L+L)%L;
		if(w==1){
			if(T>=L-a)Now=(Now+(T-L+a)/L+1)%n;
		}
		else{
			if(T>=a+1)Now=(Now-(T-a-1)/L-1+n)%n;
		}
//		cout<<Now<<endl;
	}
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define M 100005
int n;
vector<int>e[M];
int sg[M];
void dfs(int u,int f){
	int sum=0;
	for(int i=0;i<e[u].size();i++){
		int v=e[u][i];
		if(v==f)continue;
		dfs(v,u);
		sum=sum^(sg[v]+1);
	}
	sg[u]=sum;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,0);
	if(sg[1])puts("Alice");
	else puts("Bob");
	return 0;
}

Measured memory_bytes: 13952
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A, B, M = LI()
a = LI()
b = LI()
xyc = [[] for i in range(M)]
for i in range(M):
    x, y, c = LI()
    x -= 1
    y -= 1
    xyc[i] = [x, y, c]

ans = mod
for i in range(M):
    x, y, c = xyc[i]
    ans = min(ans, a[x] + b[y] - c)

ans = min(ans, min(a) + min(b))
print(ans)


Measured memory_bytes: 33520
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(m)]
s = [0 for i in range(n)]
for i in range(m):
    if h[a[i][0]-1] <= h[a[i][1]-1]:
        s[a[i][0]-1] = 1
    if h[a[i][0]-1] >= h[a[i][1]-1]:
        s[a[i][1]-1] = 1
ans = n - sum(s)
print(ans)

Measured memory_bytes: 98600
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

while True:
    a = stdin.readline().strip()
    if not a:
        break
    b = stdin.readline().strip()
    if a == b:
        print('4 0')
        continue
    hit = sum(int(a[i] == b[i]) for i in xrange(0, 7, 2))
    blow = sum(int(b[i] in a) for i in xrange(0, 7, 2)) - hit
    print(hit, blow)

Measured memory_bytes: 4240
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)


template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int main(){
    ll H, W;

    cin >> H >> W;

    ll max = H * W;
    if (H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }
    
    if (max % 2 == 1){
        cout << max / 2 + 1 << endl;
    }
    else{
        cout << max / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, m = LI()
    l = [0] * n
    for i in range(m):
        a, b = LI_()
        l[a] ^= 1
        l[b] ^= 1
    print("NO" if sum(l) else "YES")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 43116
import java.io.{PrintWriter, _}
import java.util
import java.util._


object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val a = in.nextInt
      val b = in.nextInt
      val set1 = new util.HashSet[Int]
      val set2 = new util.HashSet[Int]
      val set3 = new util.HashSet[Int]
      set1.add(1)
      set1.add(3)
      set1.add(5)
      set1.add(7)
      set1.add(8)
      set1.add(10)
      set1.add(12)
      set2.add(4)
      set2.add(6)
      set2.add(9)
      set2.add(11)
      set3.add(2)
      if ((set1.contains(a) && set1.contains(b))
        || (set2.contains(a) && set2.contains(b))
        || (set3.contains(a) && set3.contains(b))) {
        println("Yes")
      } else {
        println("No")
      }
    }
  }

  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new StringTokenizer("")


    def next: String = {
      while ( {
        tokenizer == null || !tokenizer.hasMoreTokens
      }) try
        tokenizer = new StringTokenizer(reader.readLine)
      catch {
        case e: IOException =>
          throw new RuntimeException(e)
      }
      tokenizer.nextToken
    }

    def nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


Measured memory_bytes: 25288
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		sc.close();
		
		int ans = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'g') {
				ans++;
			} else {
				ans--;
			}
		}
		
		System.out.println(ans/2);
		
		return;
	}
}

Measured memory_bytes: 13824
N, A, B = map(int, input().split())
S = list(input())

stu = 0
fstu = 0

for i in range(N):
    if S[i] == "a":
        if stu < A+B:
            stu += 1
            print("Yes")
        else:
            print("No")      
    elif S[i] == "b":
        if stu < A+B and fstu < B:
            stu += 1
            fstu += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")

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

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

  cin >> n;
  vector<string> s(n);

  for(int i = 0; i < n; i++)
    cin >> s[i];

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

  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] != s[i+1])
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9524
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int            	long long
#define tree         	ped
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<integer>
#define pint        	pair<integer, integer>
#define umint        	unordered_map<integer, integer>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

// #include "functions.h"

void om_shree_ganeshaya_namah(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

vint fact(1e5+1);

int32_t main(){
    
    om_shree_ganeshaya_namah();

    in(n);
    vint arr(n), dp(n);
    f(n) cin>>arr[i];
    dp[0] = 0; dp[1] = abs(arr[1]-arr[0]);
    for(int i=2; i<n; i++){
    	int a = dp[i-1]+abs(arr[i]-arr[i-1]);
    	int b = dp[i-2]+abs(arr[i]-arr[i-2]);
    	dp[i] = min(a, b);
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 4472
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define N 5010
#define mod 1000000007
using namespace std;
ll ksm(ll a,ll b=mod-2)
{
	if(b==1) return a;
	if(b==0) return 1;
	ll q=ksm(a,b>>1);
	if(b&1) return q*q%mod*a%mod;
	return q*q%mod;
}
ll f[N][N];
char str[N];
int main()
{
	int n,m;
	scanf("%d%s",&n,str);
	m=strlen(str);
	f[0][0]=1;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=i;j++)
		if(f[i][j]) (f[i+1][j+1]+=2*f[i][j])%=mod,(f[i+1][max(j-1,0)]+=f[i][j])%=mod;
	printf("%lld\n",f[n][m]*ksm(ksm(2,m))%mod);
	return 0;
}


Measured memory_bytes: 194176
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<cstring>
using namespace std;
int main() {
	int n;
	while(scanf("%d",&n),n){
		n = 1000 - n;
		int cnt = 0;
		if(500 <= n){
			n -= 500;
			cnt++;
		}
		if(100 <= n){
			cnt += n / 100;
			n %= 100;
		}
		if(50 <= n){
			cnt += n / 50;
			n %= 50;
		}
		if(10 <= n){
			cnt += n / 10;
			n %= 10;
		}
		if(5 <= n){
			cnt += n / 5;
			n %= 5;
		}
		cnt += n;
		printf("%d\n",cnt);
	}
    return 0;
}

Measured memory_bytes: 1188
L, R = [int(_) for _ in input().split()]
if R-L >= 2018:
    m = 0
else:
    m = 2020
    N = [i%2019 for i in range(L, R+1)]

    for i in range(len(N)):
        for j in range(i+1,len(N)):
            m = min(m, (N[i]*N[j])%2019)

print(m)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int N = S.size();
  string ans = "Yes";
  for (int i = 0; i <= (N - 1)/4; i++){
    if (S.at(i) == S.at((N - 3)/2 - i) 
        && S.at((N - 3)/2 - i) == S.at((N + 1)/2 + i)
        && S.at((N + 1)/2 + i) == S.at(N - 1 - i)){
      continue;
    }
    else {
      ans = "No";
      break;
    }
  }
  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;
const int MAX = 510000;
signed main(){
    int n;
    cin>>n;
    bool a[214514];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans[214514];
    for(int i=n-1;i>=0;i--){
        if(a[i]==true){
            ans[i]=1;
            for(int j=1;j<=sqrt(i+1);j++){
                if((i+1)%j==0){
                    a[j-1]=!a[j-1];
                    if(!((i+1)/j==j)){
                        a[(i+1)/j-1]=!a[(i+1)/j-1];
                    }
                    
                }
            }
        }else{
            ans[i]=0;
        }
    }
    int m=0;
    for(int i=0;i<n;i++){
        if(ans[i]!=0)m++;
    }
    cout<<m<<endl;
    for(int i=0;i<n;i++){
        if(ans[i]==1)cout<<i+1<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 2688
N, M = gets.split.map(&:to_i)
edges = Array.new(N) { [] }

M.times do
  a, b = gets.split.map(&:to_i)
  # 頂点は全て処理しやすいように -1 する 
  edges[a - 1].push(b - 1)
end
# スタートとゴールも -1 する
S, T = gets.split.map(&:to_i).map(&:pred)

# 距離を格納するための配列
# 3の倍数、余り1、余り2のステップで到達した時の、最短距離をそれぞれ格納
dist = Array.new(N) { Array.new(3) }
que = [[S, 0]]
# BFSでdistを埋めていく
while !que.empty?
  start, step = que.shift
  # 3つのうちどこに格納すべきか判断するための変数
  next_step = (step + 1) % 3
  edges[start].each do |edge|
    # 任意の頂点、ステップ（3の倍数か、余り1か、余り2か）が埋まっていない場合のみ埋める
    # BFSで埋めているので、先に埋めた方が最短距離であるため更新はしない
    unless dist[edge][next_step]
      dist[edge][next_step] = step + 1
      # キューにスタート地点と今までにかかったステップ数を入れる
      que.push([edge, step + 1])
    end
  end
end

ans = dist[T][0] || -3
puts ans/3

Measured memory_bytes: 18556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d[200005],f[200005],n,p,ans;
map<ll,ll> num;
ll qpow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%p;
		b=b/2;
		a=a*a%p;
	}
	return res%p;
}
int main(){
	cin>>n>>p;
	string s;
	cin>>s;
	s=" "+s;
	if(p==2||p==5){
		for(int i=1;i<=n;i++){
			if((s[i]-'0')%p==0) ans+=i;
		}
		cout<<ans<<endl;
		return 0;
	}
	for(ll i=1;i<=n;i++){
		f[i]=(f[i-1]%p+qpow((ll)10,n-i)%p*(s[i]-'0')%p)%p;
	}
	for(ll i=n;i>=1;i--){
		d[i]=(d[i+1]%p+(s[i]-'0')%p*qpow((ll)10,n-i)%p)%p;
		num[d[i]]++;
	}
	num[0]++;
	for(ll i=1;i<=n;i++){
		num[d[i]]--;
		ans+=num[(d[1]-f[i-1]+p+p)%p];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4160
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

// vector<int> make_dict(int N, vector<int> dict, int at){
// 	if (at == N)
// 		return dict;
// 	dict
// }
int factorial(int N){
	if(N == 0) return 0;
	if(N == 1) return 1;
	return N * factorial(N - 1);
}
int count(vector<int> P, int N){
	vector<bool> used(N, false);
	int count = 1;
	rep(i, N){
		int cnt = 0;
		rep(n, P.at(i)){
			// cout << "P.at(i):" << P.at(i) << "　" << n << endl;
			if (used.at(n) == false) cnt++;
				// cout << "+1" << endl;}
		}
		cnt -= 1;
		// cout << "N=" << N - 1 - i << ":" << factorial(N - 1 - i) << endl;
		count += factorial(N - 1 - i) * cnt;
		used.at(P.at(i) - 1) = true;
	}
	// cout << "count= " << count << endl;
	return (count);
}

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

	vector<int> P(N);
	vector<int> Q(N);
	rep(i, N) cin >> P.at(i);
	rep(i, N) cin >> Q.at(i);

	int ans = count(P, N) - count(Q, N);
	if (ans < 0) ans *= -1;
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
L=list(map(int,input().split()))
cnt = 0
ans = 0
for i in range(n-1):
    if L[i+1]-L[i]<=0:
        cnt += L[i+1]-L[i]
        if cnt <= -2:
            ans = 1
            break
    else:
        cnt = 0
print("Yes" if ans==0 else "No")

Measured memory_bytes: 14396
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define all(a) begin(a),end(a)
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define sz(x) ((int)x.size())
#define ins insert
#define rep(i,l,u) for(int i=l;i<=u;++i)
#define reb(i,l,u) for(int i=l;i>=u;--i)
using namespace std;
const int maxn=2e5+10;
const int mod=1e9+7;
const int inf=1e18;
main(){
    int n,m;
    cin>>n>>m;
    int l=2*n;
    int r=4*n;
    if(m>=l&&m<=r){
        if((r-m)%2)puts("No");
        else puts("Yes");
    }
    else puts("No");
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <array>

using namespace std;

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <array>

using namespace std;
using Fd = array<long long, 3>;
vector<Fd> fds;
int n;

int main() {
	long long tkhs = 0,aok  = 0;
	cin >> n;
	fds.reserve(n);
	for(int i=0; i<n; i++) {
		long long a,b;
		cin >> a >> b;
		fds.push_back({a,b,a+b});
	}
	sort(fds.begin(), fds.end(), [](Fd a, Fd b)->bool{
		return
			a[2] > b[2];
		});
	for(int i=0; i<n; i++) {
		if(i%2 == 0) {
			tkhs += fds[i][0];
		}else {
			aok += fds[i][1];
		}
	}
	cout << tkhs - aok << endl;
	return 0;
}

Measured memory_bytes: 2560