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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k) {
        out(s);
        return 0;
    }

    s = s.substr(0, k);
    s.push_back('.');
    s.push_back('.');
    s.push_back('.');
    out(s);

    return 0;
}


Measured memory_bytes: 3596
#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, n0, n1, n2, n3, i0, j0, l0;
    cin >> n;
    n3 = n%10;
    n /= 10;
    n2 = n%10;
    n /= 10;
    n1 = n%10;
    n /= 10;
    n0 = n;
    rep(i, 2) rep(j, 2) rep(l, 2){
        int sum = n0;
        if(i == 0){
            sum += n1;
        }else{
            sum -= n1;
        }
        if(j == 0){
            sum += n2;
        }else{
            sum -= n2;
        }
        if(l == 0){
            sum += n3;
        }else{
            sum -= n3;
        }
        if(sum == 7){
            i0 = i;
            j0 = j;
            l0 = l;
            break;
            break;
            break;
        }
    }
    string ans = "";
    ans += n0 + '0';
    if(i0 == 0){
        ans += '+';
    }else{
        ans += '-';
    }
    ans += n1 + '0';
    if(j0 == 0){
        ans += '+';
    }else{
        ans += '-';
    }
    ans += n2 + '0';
    if(l0 == 0){
        ans += '+';
    }else{
        ans += '-';
    }
    ans += n3 + '0';
    ans += "=7";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main() {
    val x = readLine()!!.toInt()
    println(
            when {
                x >= 1800 -> 1
                x >= 1600 -> 2
                x >= 1400 -> 3
                x >= 1200 -> 4
                x >= 1000 -> 5
                x >= 800 -> 6
                x >= 600 -> 7
                else -> 8
            }
    )
}

Measured memory_bytes: 34532
gets.to_i.times{h=Hash.new{0}
gets.to_i.times.map{gets}.map{|p|p.scan(/../).each_with_index{|s,i|h[Rational(i,p.size/2)]+=s.hex if"00"!=s}}
puts (d=h.keys.map(&:denominator).inject(1){|r,l|r.lcm l})>1024?"Too complex.":d.times.map{|i|(f=h[Rational(i,d)])?"%02X"%f :"00"}*""}

Measured memory_bytes: 7248
#include<stdio.h>

int main(){

	int a,b,c,d;

	scanf("%d %d %d %d",&a,&b,&c,&d);

	if(a>b){
		if(c>d){
			printf("%d",b+d);
		}
		else{
			printf("%d",b+c);
		}

	}	
	else{
		if(c>d){
			printf("%d",a+d);
		}
		else{
			printf("%d",a+c);
		}
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define SZ(x) ((int)(x).size())
#define TC(tc) while (tc--)
#define VI vector<int>
#define PII pair<int, int>
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() 
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	string s, t; cin >> s >> t;
	int sz = SZ(s);
	int c = 0;
	FOR(i, 0, sz)
	{
		if (s[i] != t[i]) c++;
	}
	cout << c;
}




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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;++i) {
        cin>>h[i];
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<n;++i) {
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

#define ll long long
const int MAXN = 1000005;
const int MOD = 1000000007;

class TaskE {
private:
	Debugger debugger;

	bool possible(double limit, const vector<int> &nums, int k) {
		ll needed = 0;
		for(int c : nums) {
			needed += ceil((double)c / limit) - 1;
		}
		return needed <= k;
	}

public:
	void solveOne(int it){	
		int n, k;
		cin >> n >> k;
		vector<int> nums(n);
		for(int i = 0; i < n; i++) {
			cin >> nums[i];
		}
		double le = 0, ri = 1e9;
		for(int it = 0; it < 100; it++) {
			double mid = (le+ri)/2;
			if(possible(mid, nums, k)) {
				ri = mid;
			} else {
				le = mid;
			}
		}
		ll ans = ceil(ri);
		cout << ans << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskE solver;
	solver.solve();
	return 0;
}



Measured memory_bytes: 4032
#include<stdio.h>
int main()
{
    int y,m;
    scanf("%d %d",&y,&m);
    if (y<=5)
        printf("0\n");

    else if(y>=6 && y<=12 )
        printf("%d\n",m/2);

        else if("y>=13")
            printf("%d\n",m);

            return 0;
    }


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
 int a, b, m=0,DeltaVal;
 cin >> a >> b;
 DeltaVal = b - a;
 for (int i = 0; i < DeltaVal+1; i++)
 {
  m = m + i;
 }
 
 DeltaVal = m - b;
 cout << DeltaVal;
}

Measured memory_bytes: 256
/*
{By GWj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
LL n,a[404],b[404];
const int MOD=998244353;
LL sum=0,fact[404],rfact[404];
LL quick(LL A,LL B){
	if(!B) return 1ll;
	LL tmp=quick(A,B>>1);
	tmp*=tmp;
	tmp%=MOD;
	if(B&1){
		tmp*=A;
		tmp%=MOD;
	}
	return tmp;
}
LL c(LL A,LL B){
	return fact[B]*rfact[A]%MOD*rfact[B-A]%MOD;
} 
LL dp[404][404][404][2],g[404][404][2]; 
LL inv[404][404],mi[404][404]/*(i^j)^(-1)*/;
int main(){
	fastio;
	R(n);
	LL sum2=0;
	rb(i,1,n){
		R2(a[i],b[i]); 
		sum2+=b[i];
		sum+=a[i];
	} 
	fact[0]=1ll;
	rb(i,1,400)
		fact[i]=fact[i-1]*i%MOD;
	rfact[400]=quick(fact[400],MOD-2);
	rfact[0]=1;
	rl(i,399,1){
		rfact[i]=rfact[i+1]*(i+1)%MOD;
	}
	rb(i,0,400)
		rb(j,0,400)
			inv[i][j]=quick(quick(i,j),MOD-2),mi[i][j]=quick(i,j);
	g[0][0][0]=1;
	rb(i,1,n){
		rb(k,0,b[i]-1)
			rb(s,a[i],400){
				rb(x,k,400){
					rep(p,2){
						if(!g[s-a[i]][x-k][p^1]) continue;
						dp[i][s][x][p]+=g[s-a[i]][x-k][p^1]*rfact[x-k]%MOD*fact[x]%MOD*mi[s-a[i]][x-k]%MOD*inv[s][x]%MOD*mi[a[i]][k]%MOD*rfact[k]%MOD*(s-a[i]? (s-a[i])*inv[s][1]%MOD:sum*inv[s][1]%MOD)%MOD;
						dp[i][s][x][p]%=MOD;						
					}
				}
			}
		rb(s,0,400)
			rb(x,0,400)
				rep(p,2)
					g[s][x][p]+=dp[i][s][x][p],g[s][x][p]%=MOD;
	}
	LL rest=0;
	rb(s,0,400)
		if(s)
		rb(x,0,400)
			rep(p,2){
				if(p){
					rest+=g[s][x][p];
					rest%=MOD;		
				}
				else{
					rest-=g[s][x][p];
					rest+=MOD;
					rest%=MOD;
				}
			}
//	cout<<9ll*inv[2][1]%MOD<<endl;
	cout<<rest<<endl;
	return 0;
}
/*
2
1 2
1 1

*/

Measured memory_bytes: 354836
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int mod = (int) 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

int mul(int a, int b) {
  return (long long) a * b % mod;
}

const int maxn = 3005;
int n, m;

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return false;
  }
  return true;
}

int dp[maxn][maxn][2];

int solve(int n, int m, int flag) {
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i <= n; i++) {
    dp[0][i][(i == 0 && !flag)] = 1;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j <= n; j++) {
      for (int zero = 0; zero < 2; zero++) {
        auto cur = dp[i][j][zero];
        if (!cur) {
          continue;
        }
        for (int dir = -1; dir < 2; dir++) {
          if (j + dir < 0 || j + dir > n) {
            continue;
          }
          int tomul = 1;
          if (!dir && 0 < j && j < n) {
            tomul = 2;
          }
          if (!dir && j == 0 && flag == 2) {
            tomul = 2;
          }
          int tozero = (zero || (j + dir == 0 && !flag));
          if (j == 0 && j + dir == 0) {
            tozero = 1;
          }
          add(dp[i + 1][j + dir][tozero], mul(tomul, cur));
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i <= n; i++) {
    add(res, dp[m][i][1]);
  }
  eprintf("%d\n", res);
  return res;
}

void solve() {
  int res = solve(n, m, 0);
  if (n == 1) {
    add(res, 1);
  } else {
    add(res, solve(n - 1, m, 2));
    add(res, mod - solve(n - 1, m, 1));
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 70784
from collections import deque
n = int(input())
mat=[[10**18 for i in range(n+1)] for j in range(n+1)]
ab = [[] for i in range(n)]

for i in range(n):
    si = input()
    for j in range(n):
        if int(si[j]) == 1:
            #print(i,j)
            mat[i+1][j+1] = 1
            ab[i].append(j)

colors = [0 for i in range(n)] 

#頂点vをcolor(1 or -1)で塗り、再帰的に矛盾がないか調べる。矛盾があればFalse
def dfs(v,color):
    #今いる点を着色
    colors[v] = color
    #今の頂点から行けるところをチェック
    for to in ab[v]:
        #同じ色が隣接してしまったらFalse
        if colors[to] == color:
            return False
        #未着色の頂点があったら反転した色を指定し、再帰的に調べる
        if colors[to] == 0 and not dfs(to, -color):
            return False
    #調べ終わったら矛盾がないのでTrue
    return True

#2部グラフならTrue, そうでなければFalse
def is_bipartite():
    return dfs(0,1) # 頂点0を黒(1)で塗ってDFS開始

if not is_bipartite():
    print(-1)
    exit()

#N,M=map(int,input().split())

for i in range(n+1):
	mat[i][i]=0

for i in range(1,n+1):
	for x in range(1,n+1):
		for y in range(1,n+1):
			mat[x][y] = min(mat[x][y], mat[x][i] + mat[i][y])

ans = 0

for i in range(1,n+1):
    for j in range(i+1,n+1):
        ans = max(ans,mat[i][j])
        
print(ans+1)

Measured memory_bytes: 42604
import java.util.*;

class Main {
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int Ans = 0;
      if(N<10) {
    	  Ans = N;
      }
      else if(N<100) {
    	  Ans = 9;
      }
      else if(N<1000) {
    	  Ans = N -100 +10;
      }
      else if(N<10000) {
    	  Ans = 900 + 9;
      }
      else if(N<100000) {
    	  Ans = N-10000 + 910;
      }else {
    	  Ans = 90909;
      }
      System.out.println(Ans);
  }
}

Measured memory_bytes: 21844
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"0\n"; return 0;}
#define yup {cout<<"YES\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}
 
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// Dont paste code two times in the text file.
// ============================================================

int main() {

    get(n);
    set<ll> seta;
    rep(i,n) {
        get(a);
        seta.insert(a);
    

    }
    if(seta.size()==n) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;

const int SIZE = 1e7 + 7;
int nod[SIZE];
ll ans;
class divisor {
public:
    divisor() {
        for (int i = 1; i <= SIZE; i++) {
            for (int j = 1; i * j <= SIZE; j++) {
                nod[i * j]++;
            }
        }
    }
};

divisor obj;

void solve(int num) {
    for (int i = 1; i <= num; i++) {
        ans += 1LL * i * nod[i];
    }
}

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

//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

    int num;
    cin >> num;
    solve(num);
    cout << ans << '\n';
    return 0;
}

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

// loop and test case
#define ft    int t; scanf("%d", &t); for(int c=1; c<=t; c++)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop for (i=0; i<n; i++)

//memset function
#define setz(a) memset(a, 0, sizeof(a))
#define setneg(a) memset(a, -1, sizeof(a))

#define sf scanf
#define pf printf

// integer input
#define isc(a) scanf("%d", &a)
#define isc2(a,b) scanf("%d%d", &a,&b)
#define isc3(a,b,c) scanf("%d%d%d", &a,&b,&c)

// long and long long integer input
#define lsc(a) scanf("%ld", &a)
#define lsc2(a,b) scanf("%ld%ld", &a,&b)
#define llsc(a) scanf("%lld", &a)
#define llsc2(a,b) scanf("%lld%lld", &a, &b)
#define llsc3(a,b,c) scanf("%lld%lld%lld", &a, &b, &c)

// unsign long long input
#define ullsc(a) scanf("%llu", &a)
#define ullsc2(a,b) scanf("%llu%llu", &a, &b)

// double input
#define dsc(a) scanf("%lf", &a)
#define dpf2(a) printf("%.2f", a)
#define dpf3(a) printf("%.3f", a)

//Case printing
#define casepf(a) printf("Case %d: ", a)
#define casestr(a, b) printf("Case %d: %s\n", a,b)
#define nl printf("\n") //new line

#define fl(a) floor(a)
#define cl(a) ceil(a)


#define pb(a) push_back(a)
typedef pair<int, int> pii;
#define mp(a,b) make_pair(a,b)

typedef long long ll;
typedef unsigned long long ull;
int start[2000003],finish[2000003];
int main(){
int x,T;
isc2(x,T);
for(int i=0;i<x;i++){
    isc(start[i]);
    finish[i]=start[i]+T;
}
int s=start[0];
ll sum=0;
int e=finish[0];
int flag=0;
 sum+=T;
for(int i=1;i<x;i++){
    if(start[i]<e){
        e=finish[i];
        flag=1;
    }
    else{
        if(flag==1){
           sum+=(e-s);
           sum-=T;
           flag=0;
        }
        s=start[i];
        sum+=T;
        e=finish[i];
    }
}
 if(flag==1){
           sum+=(e-s);
            sum-=T;
           //cout<<sum<<endl;
           flag=0;
        }
cout<<sum<<endl;
}


Measured memory_bytes: 5120
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;	
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) 
{
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
ll modulo = 1e9 + 7;

ll fpow(ll a, ll n) 
{
	ll ans = 1;
	while (n) 
	{
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

void solve() 
{
	ll n,a,b; cin >> n >> b >> a;
	ll ans = b * (n / (a + b));
	n %= (a + b);
	ans += min(n, b);
	cout << ans << endl;	
}

int main() 
{
	fast_io();
	int t = 1;
	// cin >> t;
	while (t--) solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long a[n];
  a[0]=2;a[1]=1;
  for(int i=2;i<=n;i++){
    a[i]=a[i-1]+a[i-2];
  }
  cout << a[n] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s;
  cin>>s;
  if(s=='A')cout<<'T'<<endl;
  if(s=='T')cout<<'A'<<endl;
  if(s=='C')cout<<'G'<<endl;
  if(s=='G')cout<<'C'<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forN(N) if(N >= 0)for(size_t i = 0;i < N;++i)

int main() {
  int N;
  vector<unsigned long> a;
  
  cin >> N;
  unsigned long T = 0;
  forN(N){
    unsigned long t;
    cin >> t;
    a.push_back(t);
    T = T^a[i];
  }
  //cout << t << endl;
  forN(N){
	cout << (T^a[i]) << endl;
  }
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#define LOCAL
#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int ans = 100000;
	int H, W, N;
	cin >> H >> W >> N;

	for (int i = 0; i <= H; ++i) {
		for (int j = 0; j <= W; ++j) {
			if ((H - i) * (W - j) <= H * W - N) {
				chmin(ans, i + j);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

int const MOD = 1e9+7;
int n, k;
int candy[101];
int dp[101][100001];

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

    dp[0][0] = 1;
    for(int i = 1; i <= n; i++)
    {
        int sum = 0;
        int l = 0;
        for(int j = 0; j <= k; j++)
        {
            sum += dp[i-1][j];
            sum %= MOD;
        
            while(l >= 0 && l < j-candy[i])
            {
                sum -= dp[i-1][l];
                sum += MOD;
                sum %= MOD;
                l++;
            }

            dp[i][j] = sum;
        }
    }

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

Measured memory_bytes: 42664
/*
 * I wish I could travel by the road that crosses baby's mind,
 * and out beyond all bounds;
 * Where messengers run errands for no cause 
 * between the kingdoms of kings of no history;
 * Where Reason makes kites of her laws and flies them, 
 * and Truth sets Fact free from its fetters.
 *                                         Rabindranath Tagore
 */

#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;

#ifndef ORZ_ZTR
#define ORZ_ZTR
#endif

#ifndef ORZ_EVERYBODY
#define ORZ_EVERYBODY
#endif

const size_t MAX_N = 1e5 + 5;

vector<int> g[MAX_N];
int n, m, cols[2];
bool col[MAX_N], used[MAX_N];

bool dfs(int v = 1, int cl = 0) {
    for (int& x: g[v]) if (used[x] && col[x] == cl) return false; 
    col[v] = cl;
    ++cols[cl];
    bool ok = used[v] = true;
    for (int& x: g[v]) if (!used[x] && !dfs(x, !cl)) {
        ok = false;
        break;
    }
    return ok;
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0, a, b; i < m; ++i) {
        scanf("%d%d", &a, &b);
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    if (!dfs()) return cout << 1LL * n * (n - 1) / 2 - m, 0;
    return cout << 1LL * cols[0] * cols[1] - m, 0;
}


Measured memory_bytes: 6272
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int dp[10010];
int main()
{
    int h,n,a[1010],b[1010];
    cin>>h>>n;
    REP(i,n)cin>>a[i]>>b[i];

    REP(i,h+1)dp[i]=1e9;
    dp[0]=0;

    REP(i,n)
    {
        // REP(j,h+1)cout<<dp[j]<<" ";cout<<endl;
        REP(j,h)
        {
            int to=min(h,j+a[i]);
            dp[to]=min(dp[to],dp[j]+b[i]);
        }
    }
    // REP(i,h+1)cout<<dp[i]<<" ";cout<<endl;
    cout<<dp[h]<<endl;
}


Measured memory_bytes: 384
def solve(s):
    if all(a == b for a, b in zip(s, s[1:])):
        return 1
    if len(s) == 2:
        return 2
    elif len(s) == 3:
        if s[0] == s[1] or s[1] == s[2]:
            return 6
        elif s[0] == s[2]:
            return 7
        else:
            return 3
    # dp[has succession=0][mod 3][last char], dp[has succession=1][mod 3]
    dp = [[[0] * 3 for _ in range(3)], [0] * 3]
    dp[0][0][0] = 1
    dp[0][1][1] = 1
    dp[0][2][2] = 1
    MOD = 998244353
    for _ in range(len(s) - 1):
        ndp = [[[0] * 3 for _ in range(3)], [0] * 3]
        dp0, dp1 = dp
        ndp0, ndp1 = ndp
        sdp1 = sum(dp1)
        ndp0[0][0] = (dp0[0][1] + dp0[0][2]) % MOD
        ndp0[1][0] = (dp0[1][1] + dp0[1][2]) % MOD
        ndp0[2][0] = (dp0[2][1] + dp0[2][2]) % MOD
        ndp0[0][1] = (dp0[2][0] + dp0[2][2]) % MOD
        ndp0[1][1] = (dp0[0][0] + dp0[0][2]) % MOD
        ndp0[2][1] = (dp0[1][0] + dp0[1][2]) % MOD
        ndp0[0][2] = (dp0[1][0] + dp0[1][1]) % MOD
        ndp0[1][2] = (dp0[2][0] + dp0[2][1]) % MOD
        ndp0[2][2] = (dp0[0][0] + dp0[0][1]) % MOD
        ndp1[0] = (dp0[0][0] + dp0[1][2] + dp0[2][1] + sdp1) % MOD
        ndp1[1] = (dp0[1][0] + dp0[2][2] + dp0[0][1] + sdp1) % MOD
        ndp1[2] = (dp0[2][0] + dp0[0][2] + dp0[1][1] + sdp1) % MOD
        dp = ndp
    return (dp[1][sum(map(ord, s)) % 3] + all(a != b for a, b in zip(s, s[1:]))) % MOD


s = input()
print(solve(s))


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



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
 
 
//defines
typedef long long ll;
typedef long double ld;

    
ll a,b,c,n,m,k,t=1;

void solve()
{
   cin>>n>>m;
   for(ll i=0;i<=n;i++)
   {
       if(i*2+(n-i)*4==m)
       {
           cout<<"Yes";return;
       }
   }
   
   cout<<"No";
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

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

#define YEAR 365
#define SNUM 3
#define MAXK 30

int main(void){
	int kaidan[MAXK];
	int knum;
	int kyear;

	while(1){
		//init
		for(int i=SNUM; i<MAXK; i++)
			kaidan[i]=0;
		for(int i=0; i<SNUM; i++)
			kaidan[i]=1;
		//in
		cin >> knum;
		if(knum==0)break;

		//calc
		for(int i=0; i<knum; i++){
			for(int k=1; k<=SNUM&&k+i<knum; k++)
				kaidan[i+k] = kaidan[i+k] + kaidan[i];
		}
		kyear = kaidan[knum-1] / (365*10) + 1;

		//out
		cout << kyear << endl;
	}

	return 0;
}

Measured memory_bytes: 0
n = int(input())

pre = [[0]]
ans = [[0]]
s = 'abcdefghijklmnop'

for i in range(n-1):
    ans = []
    for item in pre:
        for j in range(max(item)+2):
            ans.append(item + [j])
    pre = ans[:]

res = []
for item in ans:
    print("".join([s[c] for c in item]))


Measured memory_bytes: 26276
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

bool getans(char c, bool prev, bool now) {
    bool ret;
    if (now) {   // W
        if (c == 'o') {
            ret = !prev;
        } else {    // x
            ret = prev;
        }
    } else {    // S
        if (c == 'o') {
            ret = prev;
        } else {    // x
            ret = !prev;
        }
    }
    return ret;
}

bool valid(char c,bool prev,bool now, bool next) {
    bool ret;
    if (now) { // W
        if (c == 'o') {
            ret = prev != next;
        } else {
            ret =  prev == next;
        }
    } else {
        if (c == 'o') {
            ret = prev == next;
        } else {
            ret = prev != next;
        }
    }
    return ret;
}

int main(void)
{
    IOS
    constexpr int N = 1e5;
    int n; cin >> n;
    string s; cin >> s;
    int l = s.size();

    REP(i,4) {
        bitset<N+10> ans(i);

        FOR(j,1,l-1){
            ans[j+1] = getans(s[j],ans[j-1],ans[j]);
        }

        if (!valid(s[l-1],ans[l-2],ans[l-1],ans[0])) continue;
        if (!valid(s[0],ans[l-1],ans[0],ans[1])) continue;

        string astr = "";
        REP(j,l){
            astr += ans[j] ? "W" : "S";
        }
        cout << astr << endl;
        return 0;
    }
    cout << "-1" << endl;


    return 0;
}

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

int main(){
  int n;
  int Acard,Bcard;
  int Atotal,Btotal;
while(true){
  cin>>n;
  if(n==0){
    break;
  }
  for(int i=0;i<n;i++){
    cin>>Acard>>Bcard;
    if(Acard>Bcard){
      Atotal+=Acard+Bcard;
    }else if(Bcard>Acard){
      Btotal+=Acard+Bcard;
    }else{
      Atotal+=Acard;
      Btotal+=Bcard;
    }
  }

  cout<<Atotal<<' '<<Btotal<<'\n';
  Atotal=0;
  Btotal=0;
}
  return 0;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
  ll n, even=0, a;
  cin >> n;
  forll(i, 0, n){
	cin >> a;
	if (a % 2 == 0)
	  even++;
  }
  cout << pow(3, n) - pow(2, even) << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> a;
    a.push_back(1);
    for(int i = 0; i < N; ++i){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    int count = 0;
    int now = 1;
    for(;;){
        now = a[now];
        count++;
        if(now == 2){
            cout << count << endl;
            break;
        }
        if (count >= N){
            cout << "-1" << endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;

#define sz(a) (int)(a).size()
#define pb push_back
typedef long long ll;

void solve() {
    string s;
    cin >> s;

    ll k;
    cin >> k;
    --k;

    if (s[0] != '1') {
        cout << s[0];
        return;
    }

    ll i = 0;
    while (i < sz(s) - 1 && s[i] == '1' && s[i] == s[i + 1]) {
        i++;
    }

    if (i >= k) {
        cout << "1";
    } else {
        cout << s[i + 1];
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 384
// Gaurav Aggarwal
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif  

    ll n,k;
    cin>>n>>k;
    ll r,ss,p;
    cin>>r>>ss>>p;
    string s;
    cin>>s;
    string f= "";

    ll ans = 0;
    for(int i=0;i<k;++i) {

    	if(s[i] == 'r') {
    		ans += p;
    		f += 'p';
    	}
    	else if(s[i] == 's') {
    		ans += r;
    		f += 'r';
    		// cout<<'r';
    	}
    	else {
    		ans += ss;
    		f += 's';
    		// cout<<'s';
    	}


    }

    for(int i=k;i<n;++i) {
    	if(s[i] == 'r') {
    		if(f[i-k] != 'p') {
    			ans += p;
    			f += 'p';
    		}
    		else {
    			if(s[i-k] == f[i-k]) {
    				ans += p;
    				f += 'p';
    			}
    			else
    				f += 'r';
    		}
    	}
    	else if(s[i] == 's') {
    		if(f[i-k] != 'r') {
    			ans += r;
    			f += 'r';
    		}
    		else {
    			if(s[i-k] == f[i-k]) {
    				ans += r;
    				f += 'r';
    			}
    			else
    				f += 's';
    		}
    	}
    	else {
			if(f[i-k] != 's') {
				ans += ss;
				f += 's';
			}
    		else {
    			if(s[i-k] == f[i-k]) {
    				ans += ss;
    				f += 's';
    			}
    			else
    				f += 'p';
    		}
    	}
    }

    cout<<ans<<"\n";


    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    char c1, c2;
    cin >> c1 >> c2;
    if(c1 < c2)     cout << "<\n";
    else if(c1 == c2)   cout << "=\n";
    else            cout << ">\n";
}

Measured memory_bytes: 256
/*ID:PROG:LANG:*/
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 998244353
#define MAXN 200005
using namespace std;
int n,fg,S;
LL ans,dp[MAXN][3][3][2];
char s[MAXN];
int rd(){
	int x=0,tp=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')tp=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x*10+c-'0');c=getchar();}
	return x*tp;
}
int main(){
	// freopen("testdata.in","r",stdin);
	// freopen("1.out","w",stdout);
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=2;i<=n;i++)fg|=(s[i]!=s[i-1]);
	if(!fg){printf("1\n");return 0;}
	if(n<=3){
		if(n==2)printf("2\n");
		if(n==3){
			if(s[1]!=s[2] && s[2]!=s[3] && s[1]!=s[3])printf("3\n");
			else if(s[1]==s[3])printf("7\n");
			else printf("6\n");
		}
		return 0;
	}
	dp[1][0][0][0]=dp[1][1][1][0]=dp[1][2][2][0]=1,fg=0;
	//dp[i][j][k][p]表示前i位，前i位的和模3意义下是j，这一位的是k，是否有相邻的两位相同
	for(int i=1;i<n;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
				for(int p=0;p<2;p++)
					for(int nex=0;nex<3;nex++)
						(dp[i+1][(j+nex)%3][nex][(k==nex)|p]+=dp[i][j][k][p])%=MOD;
	for(int i=1;i<=n;i++)S+=s[i]-'a';S%=3;
	for(int i=0;i<3;i++)(ans+=dp[n][S][i][1])%=MOD;
	for(int i=2;i<=n;i++)fg|=(s[i]==s[i-1]);//S==T
	if(!fg)ans=(ans+1)%MOD;
	printf("%lld\n",ans);
	// printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 28544
#include<iostream>
using namespace std;
int H,N;

int main(){
    cin >> H >> N;
    int A[N];
    int sum=0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum+=A[i];
    }
    if(H<=sum) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
        	double a=scan.nextDouble();
        	Double b=scan.nextDouble();
        	Double c=scan.nextDouble();
        	Double d=scan.nextDouble();
        	Double e=scan.nextDouble();
        	Double f=scan.nextDouble();
        	Double x,y;
        	x =(e*c-b*f)/(a*e-b*d);
        	y =(-d*c+a*f)/(a*e-b*d);
        	if(x==0)x=0.;
        	if(y==0)y=0.;
        	System.out.printf("%.3f %.3f\n",x,y);
        }
    }
}

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

N,M = map(int, input().split())
abM = [list(map(int, input().split())) for i in range(M)]

abM.sort()

tmp_e = abM[0][1]
cnt = 1

for i in range(1,M):
    if tmp_e > abM[i][0]:
        tmp_e = min(abM[i][1], tmp_e)
    else:
        cnt += 1
        tmp_e = abM[i][1]
print(cnt)

Measured memory_bytes: 27868
n = int(input())
response_list = [ int(v) for v in input().split() ]

ans = 0

mod = 10**9+7


if n % 2 == 0:
	right_list = [ 2*(i//2+1)-1 for i in range(n) ]
else:
	right_list = [ 2*((i+1)//2) for i in range(n) ]

if sorted(response_list) == right_list:

	if n % 2 == 0:
		ans = pow(2,n//2,mod)
	else:
		ans = pow(2,(n-1)//2,mod)

print(ans)

Measured memory_bytes: 13880
#include <iostream>

long int N = 0;
int arr[] = {7, 5, 3};

bool all(std::string target, std::string research){
    for (char c:research){
        auto it = target.find(c);
        if (it == std::string::npos){
            // 見つからなかったらFalse
            return false;
        }
    }
    return true;
}

long int shichiGoSan(long int x){
    if (x > N){
        return 0;
    }
    int ret = 0;
    if (all(std::to_string(x),"753")){
        ret = 1;
    } else {
        ret = 0;
    }
    for (int y:arr){
        ret += shichiGoSan((x * 10) + y);
    }
    return ret;
}

int main(){
    std::cin >> N;
    std::cout << shichiGoSan(0) << std::endl;
    
    return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n,m;cin>>n>>m&&n|m;){
		vl xs(n),ys(m);
		rep(i,n) cin>>xs[i];
		rep(i,m) cin>>ys[i];

		ll tmp=0;
		rep(i,n-1){
			ll w=(xs[i+1]-xs[i])*(i+1)*(n-1-i)%MOD;
			(tmp+=w)%=MOD;
		}
		ll res=0;
		rep(i,m-1){
			ll w=(ys[i+1]-ys[i])*(i+1)*(m-1-i)%MOD;
			(res+=tmp*w%MOD)%=MOD;
		}
		cout<<res<<endl;
	}
}


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

typedef long long ll;

class SegmentTree {
private:
    int n;
    vector<int> node;

public:
	SegmentTree(vector<int> v) {
        int size = v.size();
		n = 1; while(n < size) n *= 2;
		node.resize(2 * n - 1);

		for(int i = 0; i < size; i++) node[i + n - 1] = v[i];
		for(int i = n - 2; i >= 0; i--) node[i] = node[2 * i + 1] | node[2 * i + 2];
	}

	void update(int x, int val) {
		x += n - 1;

		node[x] = val;
		while(x > 0){
			x = (x - 1) / 2;
			node[x] = node[2 * x + 1] | node[2 * x + 2];
		}
	}

	int get(int a, int b, int k = 0, int l = 0, int r = -1) {
		if(r < 0) r = n - 1;
		if(r < a || b < l) return 0;
		if(a <= l && r <= b) {
            //cerr << k << " " << node[k] << endl;
            return node[k];
        }

		int vl = get(a, b, 2 * k + 1, l, (l + r - 1) / 2);
		int vr = get(a, b, 2 * k + 2, (l + r + 1) / 2, r);
		return vl | vr;
	}
};

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

    int N, Q;
    string S;

    cin >> N >> S >> Q;

    vector<int> b(N);

    for(int i = 0; i < N; i++) {
        char c = S[i] - 'a';
        b[i] = 1 << c;
    }

    SegmentTree st(b);

    vector<int> A(Q);
    vector<int> B(Q);
    vector<int> C(Q);

    for(int i = 0; i < Q; i++) {
        cin >> A[i] >> B[i];
        B[i]--;
        if(A[i] == 1) {
            char c;
            cin >> c;
            c -= 'a';
            C[i] = 1 << c;
        } else {
            cin >> C[i];
            C[i]--;
        }
    }

    for(int i = 0; i < Q; i++) {
        if(A[i] == 1) {
            st.update(B[i], C[i]);
        } else {
            cout << __builtin_popcountll(st.get(B[i], C[i])) << endl;
        }
    }
}


Measured memory_bytes: 8860
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[44];
  a[0]=1;
  a[1]=1;
  for(int i=2;i<=44;i++)a[i]=a[i-1]+a[i-2];
  int n;
  cin>>n;
  cout<<a[n]<<endl; 
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
*A, = map(int, input().split())
A = [0] + A + [0]
S = 0
for i in range(1, N+2):
    S += abs(A[i] - A[i-1])
for i in range(1, N+1):
    new = abs(A[i-1] - A[i+1])
    pre_to_now = abs(A[i-1] - A[i])
    now_to_next = abs(A[i] - A[i+1])
    print(S - pre_to_now - now_to_next + new)

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

map<int,int> heap; // 
map<char,int> var; // value of variable
int hsize,maxhs,ridx,rvalue;
string in;

bool expr(int idx) {
    if(idx+1 < in.length() && in[idx+1] == '=') { // assignment
        bool inner = expr(idx+2);
        var[in[idx]] = rvalue;
        return inner;
    }else if(in[idx] == 'm') {// malloc
        int s = 0,tidx = idx+7;
        while(isdigit(in[tidx])) {
            s *= 10;
            s += in[tidx] - '0';
            tidx++;
        }

        ridx = tidx+1;
        if(hsize + s > maxhs) rvalue = -1;
        else{
            hsize += s;
            rvalue = heap.size();
            heap[rvalue] = s;
        }

    }else if(in[idx] == 'c') {// clone
        bool inner = expr(idx+6);
        assert(in[ridx] == ')');

        ridx++;
        if(!inner) return false;
        if(rvalue == -1) return true; // NULL
        if(rvalue == -2 || heap.find(rvalue) == heap.end())
            return false;

        int s = heap[rvalue];
        if(hsize+s > maxhs) rvalue = -1;
        else{
            rvalue = heap.size();
            heap[rvalue] = s;
            hsize += s;
        }

    }else if(idx+1 < in.length() && in[idx] == 'N' && in[idx+1] == 'U') {// NULL
        ridx = idx+4;
        rvalue = -1;
    }else if(in[idx] == '(') {
        bool inner = expr(idx+1);
        ridx++;
        return inner;
    }else{ // variable
        ridx = idx+1;
        rvalue = var[in[idx]];
    }
    return true;
}

bool line() {
    if(in[0] == 'f'){// free
        bool inner = expr(5);

        if(!inner) return inner;
        if(rvalue == -1) return true;
        if(heap.find(rvalue) == heap.end()) return false;

        hsize -= heap[rvalue];
        heap.erase(heap.find(rvalue));
        return true;
    }else
        return expr(0);
}

int main() {
    cin>>maxhs;

    heap.clear(); var.clear();
    for(char c = 'A'; c <= 'Z'; ++c)
        var[c] = -2;

    bool haderror = false;
    while(cin>>in) if(!line()) haderror = true;

    if(haderror) {
        cout<<"Error"<<endl;
        return 0;
    }

    int ans = 0;
    for(map<int,int>::iterator it = heap.begin(); it != heap.end(); ++it) {
        if(it->second < 0) continue;
        bool refed = false;
        for(map<char,int>::iterator it2=var.begin(); it2 != var.end(); ++it2) {
            if(it2->second == it->first) {
                refed = true;
                break;
            }
        }
        if(!refed) ans += it->second;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 0
# n = int(input())
n,k = [int(j) for j in input().split()]
dif = [False for i in range(n)]
for i in range(k):
	d = input()
	l = [int(j) for j in input().split()]
	for j in l:
		dif[j-1] = True
print(dif.count(False))

Measured memory_bytes: 67804
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,dep[N];
vector<int> e[N];
bool vis[N],test;
void dfs(int x){
	vis[x]=1;
	for (int i=0;i<e[x].size();i++){
		int v=e[x][i];
		if (vis[v]){
			if (dep[x]==dep[v]) test=0;
			continue;
		}
		dep[v]=dep[x]^1;
		dfs(v);
	}
}
int points,bipartites,graphs;
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	for (int i=1;i<=n;i++)
	if (!vis[i]){
		test=1;dfs(i);
		if (!test) graphs++;else
		if (e[i].size()) bipartites++;else
		points++;
	}
	long long ans=0;
	ans+=1ll*points*points+2ll*points*(n-points);
	ans+=1ll*graphs*graphs+2ll*graphs*bipartites;
	ans+=2ll*bipartites*bipartites;
	printf("%lld\n",ans);
	return 0;
}

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

int main()
{
  int x,a,b;
  cin >> x >> a >> b;
  x -= a;
  cout << x % b << endl;
  system("pause");
  return 0;
}


Measured memory_bytes: 504
s = input()
n = len(s)
flg = 1
lis = []
if s[-1] == '1':
    print('-1')
    flg = 0
else:
    for i in range(n//2):
        if s[i] == s[n-2-i]:
            lis.append(int(s[i]))
        else:
            print('-1')
            flg = 0
            break
if flg ==1:
    if lis[0] == 0:
        print('-1')
    else:
        posl = []
        for i in range(1,len(lis)):
            pos = i+1
            if lis[i]==1:
                posl.append(pos)
        old = 1
        for pos in posl:
            for i in range(old,pos):
                print('{} {}'.format(i,pos))
            old=pos
        print(('{} {}'.format(old,old+1)))
        for i in range(old+2,n+1):
            print(('{} {}'.format(old+1,i)))

Measured memory_bytes: 6744
import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List (foldl')
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  [n, l] <- map read <$> words <$> getLine
  solve n l <$> replicateM n (readi B.readInt <$> B.getLine) >>= print

solve :: Int -> Int -> [Int] -> Int
solve n l xs = V.maximum $ foldl' (\t i -> fst $ f t i) tm [1..n]
  where icv = V.fromList $ 0 : (xs ++ [0])
        tm = V.replicate (n+1) 0
        f t i | t ! i > 0 = (t, t ! i)
              | lc > lp && lc > ln = (t // [(i, l - lc)], l - lc)
              | lc < lp && lc < ln = let (t1, x) = f t (i-1)
                                         (t2, y) = f t1 (i+1)
                                         z = (l - lc) + max x y
                                     in (t2 // [(i, z)], z)
              | lc < lp = let (t1, x) = f t (i-1)
                              z = (l - lc) + x
                          in (t1 // [(i, z)], z)
              | otherwise = let (t1, x) = f t (i+1)
                                z = (l - lc) + x
                                in (t1 // [(i, z)], z)
          where lc = icv ! i
                lp = icv ! (i-1)
                ln = icv ! (i+1)

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n



Measured memory_bytes: 65328