akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>
#include <fstream>
#include <codecvt>

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };



signed main() {
	ios::sync_with_stdio(true);
	
	int sum = 0;
	int a, b, c;
	cin >> a >> b >> c;
	sum = a + b + c;
	if (sum >= 22) cout << "bust" << endl;
	else cout << "win" << endl;

	return 0;
}

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

#define HAS_TEST_CASE 0

namespace rG{

typedef long long ll;

const int N=5e5;

int n,m,k,a[N+10];
char s[N+10];

inline void main(){
	int x;
	scanf("%d",&x);
	if(x==0)puts("1");
	else puts("0");
}

} // namespace rG

int main(){
#if defined(LOCAL)&&HAS_TEST_CASE
	freopen("tmp.out","w",stdout);
#endif
#if HAS_TEST_CASE
	int T;
	scanf("%d",&T);
	while(T--)rG::main();
#else
	rG::main();
#endif
	return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
 
using namespace std;
 
int main(void) {
  long H;
  cin >> H;
  long cnt = 1;
  long sum = 1;
  while (H > 1) {
    H /= 2;
    cnt *= 2;
    sum += cnt;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

      int n = Integer.parseInt(br.readLine());
      int[] seqS = new int[n];
      String[] line = br.readLine().split(" ");
      int cnt=0;
      for (String s : line)
        seqS[cnt++] = Integer.parseInt(s);

      int q = Integer.parseInt(br.readLine());
      line = br.readLine().split(" ");
      
      cnt=0;
      for (String ref : line) {
        if( isExistSeachByBinary(seqS, Integer.parseInt(ref)) )
          cnt++;
      }

      System.out.println(cnt);
    }
  }

  static boolean isExistSeachByBinary(int[] tar, int ref) {
    int left = 0;
    int right= tar.length;
    int mid;
    while( left < right ) {
      mid  = (left + right) / 2;
      if( tar[mid] == ref ) return true;
      else if( tar[mid] > ref ) right = mid;
      else left = mid + 1;
    }

    return false;
  }
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<long int> input(N + 1);
    input[0] = 0;
    for (int i = 1; i <= N; ++i) {
        cin >> input[i];
        input[i] += input[i - 1];
    }
    vector<long int> answer;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            answer.push_back(input[j] - input[i]);
        }
    }
    // sort(answer.begin(), answer.end(), greater<>());
    long int ans = 0;
    for (int i = 41; i >= 0; --i) {
        int checkOverK = 0;
        long int x = ans + (long int)pow(2, i);
        for (long j : answer) {
            if((x& j) == x) ++checkOverK;
        }
        if (checkOverK >= K) ans = x;
    }
    // cout << ans << endl;
    cout << ans << endl;
}


Measured memory_bytes: 6384
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble(); 
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		
		double xy =  (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		
		double dist = Math.sqrt(xy);
		
		System.out.println(dist);
			
		
	}

}



Measured memory_bytes: 27952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(int i = a; i < b; i++)
#define endl "\n"
const int mod = 1e9+7;
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int power(int a,int b){ int res=1; a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) { return b?gcd(b,a%b):a;}

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  set<string> se;
  vector<string> S(N);
  rep(i, N) {
    cin >> S[i];
    se.insert(S[i]);
  }
  cout << se.size() << endl;
  return 0;
}


Measured memory_bytes: 25172
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

struct edge {
    int to, cost;
};

int V;
vector<edge> G[1000000];

plglg visit(int pre, int v) {
    plglg ans(0, v);
    queue<tlglglg> que;
    tlglglg start(-1, v, 0);
    que.push(start);
    while (que.size() > 0) {
        tlglglg p;
        p = que.front();
        que.pop();
        ll back = get<0>(p);
        ll now = get<1>(p);
        ll weight = get<2>(p);
        int n = G[now].size();
        for (int i = 0; i < n; i++) {
            edge e = G[now][i];
            if (e.to != back) {
                tlglglg pp(now, e.to, weight + e.cost);
                que.push(pp);
                if (weight + e.cost > ans.first) {
                    ans.first = weight + e.cost;
                    ans.second = e.to;
                }
            }
        }
    }
    return ans;
}

pii farthest;

ll diameter() {
    plglg r = visit(-1, 0);
    plglg t = visit(-1, r.second);
    farthest.first = r.second;
    farthest.second = t.second;
    return t.first;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        edge e1;
        e1.to = t;
        e1.cost = w;
        G[s].push_back(e1);
        edge e2;
        e2.to = s;
        e2.cost = w;
        G[t].push_back(e2);
    }
    ll ans = diameter();
    cout << ans << endl;
}



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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int res = 0;
    res += min(a, k);
    k -= min(a, k);
    k -= min(k, b);
    res -= min(c, k);
    cout << res << "\n";

}



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

    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>

#define int long long

signed main() {
  int a, v, b, w, t;
  std::cin >> a >> v >> b >> w >> t;
  
  if(abs(a-b) <= t*(v-w))
    std::cout << "YES";
  else
    std::cout << "NO";
  
  std::cout << std::endl;
  return 0;
}


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

int main(){
	double l, r;
	int la=0,lb=0,lc=0,ld=0;
	int ra=0,rb=0,rc=0,rd=0;
	while(cin >> l >> r){
		if(l >= 1.1){
			la++;
		}
		else if(l >= 0.6){
			lb++;
		}
		else if(l >= 0.2){
			lc++;
		}
		else{
			ld++;
		}

		if(r >= 1.1){
			ra++;
		}
		else if(r >= 0.6){
			rb++;
		}
		else if(r >= 0.2){
			rc++;
		}
		else{
			rd++;
		}
	}
	cout << la << " " << ra << endl;
	cout << lb << " " << rb << endl;
	cout << lc << " " << rc << endl;
	cout << ld << " " << rd << endl;
}

Measured memory_bytes: 1224
import sys
input = lambda: sys.stdin.readline().rstrip()
from itertools import combinations_with_replacement as cwr , combinations , permutations ,product
from math import sqrt
a=[]
for _ in range(int(input())):
    a.append([int(i) for i in input().split()])
p=list(permutations(a))
ans=[]
for i in p:
    cur=0
    for j in range(len(i)-1):
        cur+=sqrt((i[j+1][0]-i[j][0])**2+(i[j+1][1]-i[j][1])**2)
    ans.append(cur)
print(sum(ans)/len(ans))
    


Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, l, r;
  cin >> a >> b >> c >> d;
  l = a + b;
  r = c + d;
  if (l > r){
    cout << "Left" << endl;
  }
  else if (l == r){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;

struct Node{
    int key;
    Node *parent,*left,*right;
};

Node *NIL, *root;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(z->key < x->key) //xはzのkey値と比較するためのもの
            x=x->left;
        else
            x=x->right;
    }
    z->parent=y;
    if(y == NIL){
        root = z;
    }
    else if(z->key < y->key)
        y->left = z;
    else
        y->right = z;
}
    
void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}
void preorder(Node *u){
    if(u == NIL)return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}
    
int main() 
{
    int n,x;
    string com;
  	cin >> n;
    rep(i,n){
        cin >> com;
        if(com == "insert"){
            cin >> x;
            insert(x);
        }
        else if(com == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
}


Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K, A, B;
  cin >> K >> A >>B;
  string ans = "NG";
  for(int i=0; i<1000; i++){
    if(K*i >= A && K*i <= B){
      ans = "OK";
      break;
    }
  }
    cout << ans <<endl;
  }

Measured memory_bytes: 3628
a,b,c,x,y=map(int,input().split())
if (a+b)>2*c:
    if x>y:
        if a>2*c:
            print(y*2*c+(x-y)*c*2)
        else:
            print(y*2*c+(x-y)*a)

    else:
        if b>2*c:
            print(x*2*c+(y-x)*c*2)
        else:
            print(x*2*c+(y-x)*b)
else:
    print(x*a+y*b)

Measured memory_bytes: 9136
#https://qiita.com/chun1182/items/ddf2b6cba932b2bb0d4e
def BF(p,n,s):
    inf=float("inf")
    d=[inf for i in range(n)]
    d[s-1]=0
    for i in range(n+1):
        for e in p:
            if e[0]!=inf and d[e[1]-1]>d[e[0]-1]+e[2]:
                d[e[1]-1] = d[e[0]-1] + e[2]
        if i==n-1:t=d[-1]
        if i==n and t!=d[-1]:
            return [0,'inf']
    return list(map(lambda x:-x, d))

n,m=map(int,input().split())
g=[]
for _ in range(m):
  a,b,c=map(int,input().split())
  g.append([a,b,-c])
print(BF(g,n,1)[-1])

Measured memory_bytes: 3392
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<set>
#include<bitset>
#include<map>
#include<iostream>
#define ll long long
#define rep(i,a,b) for(register ll i=a;i<=b;++i)
#define fd(i,a,b) for(register int i=a;i>=b;--i)
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Abs(a) ((a<0)?-(a):(a))
namespace io{
//    char buf[1<<17],*p1=buf,*p2=buf;
//    inline int getc(){
//         return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<17,stdin),p1==p2)?EOF:*p1++;
//    }
	#define getc() getchar()
    template<class T>
    inline void Read(T &x){
        x=0;T f=1;char c;
        for(c=getc();c<'0'||c>'9';f=((c=='-')?-1:f),c=getc());
        for(;c>='0'&&c<='9';x=x*10+(c^48),c=getc());
        x*=f;
    }
    template<class T>
    inline void write(T a){
        if(a==0){putchar('0');return;}
        if(a<0)putchar('-'),a=-a;
        char c1[120];
        int h=0;
        while(a)c1[++h]=a%10+'0',a/=10;
        for(int i=h;i>=1;i--)putchar(c1[i]);
        return;
    }
    template<class T>
    inline void write_(T a){write(a);putchar(' ');}
    template<class T>
    inline void writeln(T a){write(a);putchar('\n');}
}
using namespace io;
template<class T>
inline T gcd(T a,T b){return a==0?b:gcd(b%a,a);}
template<class T>
inline T lcm(T a,T b){return 1ll*a/gcd(a,b)*b;}
/*----------------------------------------------------------------------*/
ll l, r, ans = 20202;

int main(){
	Read(l);Read(r);
	ll teml = l / 673;ll temr = r / 673;
	if ((teml != temr && r - l + 1 >= 3) || l % 2019 == 0 || r % 2019 == 0) writeln(0);
	else {
		rep(i, l, r){
			rep(j, i + 1, r) ans = std::min(ans, (i * j) % 2019);
		}
		writeln(ans);
	}
	return 0;
}

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

int main() {
  int a1, a2, a3, temp;
  cin >> a1 >> a2 >> a3;

  if (a1 > a2) {
    temp = a1;
    a1 = a2;
    a2 = temp;
  }
  if (a2 > a3) {
    temp = a2;
    a2 = a3;
    a3 = temp;
  }
  if (a1 > a2) {
    temp = a1;
    a1 = a2;
    a2 = temp;
  }

  cout << a1 << " " << a2 << " " << a3 << endl;
}

Measured memory_bytes: 1164
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] str = line.split(" ");
        ArrayList<Integer> array = new ArrayList<Integer>();
        for(int i=0;i<str.length;i++){
        	if(!str[i].equals("+")&&!str[i].equals("-")&&!str[i].equals("*")){
        		int tmp = Integer.parseInt(str[i]);
                array.add(tmp);
        	}else{
    			int n_1 = array.get(array.size()-1);
    			array.remove(array.size()-1);
    			int n_2 = array.get(array.size()-1);
    			array.remove(array.size()-1);
        		if(str[i].equals("+")){
        			array.add(n_1+n_2);
        		}else if(str[i].equals("-")){
        			array.add(n_2-n_1);
        		}else if(str[i].equals("*")){
        			array.add(n_1*n_2);
        		}
        	}
        }
    	System.out.println(array.get(array.size()-1));
	}
}

Measured memory_bytes: 24376
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author P.Alizadeh
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll,ll>     pll;

#define all(x)          x.begin(),x.end()
#define Sort(x)         sort(all(x))
#define trace(x)        cerr << #x << " = " << x << endl;
#define X               first
#define Y               second
#define sep             " "
#define endl            "\n"
#define fastio          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define ld_io           cout << setprecision(10) << fixed;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll md) {
    if (!b)
        return 1;
    if (b & 1)
        return a * pw(a * a % md, b / 2, md) % md;
    return pw(a * a % md, b / 2, md) % md;
}

const ll MAXN = 2e5 + 10,
         INF  = 8e18,
         MOD  = 1e9 + 7;
//const ld PI   = acos(-1);

ll n, h[MAXN], dp[MAXN];

int main()
{
    fastio;
    //ld_io;

    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> h[i+1];
    }

    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for (ll i = 3; 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] << endl;

    return 0;
}



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

void swap(int &x, int &y) {
    int temp;
    temp = x;
    x = y;
    y = temp;
    return;
}

void bubbleSort(int *A, int N, int &count) {
    int flag = 1, j;
    while(flag) {
        flag = 0;
        for(j=N-1; j>0; --j) {
            if(A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                flag = 1;
                ++count;
            }
        }
    }
    return;
}

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

    bubbleSort(A, N, count);
    cout << A[0];
    for(i=1; i<N; ++i) cout << ' ' << A[i];
    cout << endl;
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
#include <bitset>
#include <memory>

int main() {
	int a, p; std::cin >> a >> p;
	std::cout << (3 * a + p) / 2 << std::endl;
}


Measured memory_bytes: 504
// 1 から n までの数の中から、重複無しで３つの数を選びそれらの合計が x となる組み合わせの数を求めるプログラムを作成して下さい。
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String str = null;
		String[] spl = new String[2];
		int i, j, k;
		int n, x, comp;
		int result = 0;

		while(true){
			result = 0;
			str = scan.nextLine();
			spl = str.split(" ");
			n = Integer.parseInt(spl[0]);
			x = Integer.parseInt(spl[1]);

			if(n==0 && x==0){
				break;
			}
			// 3重ループで重複なしでの足し算組み合わせ特定、カウンタを1増やす
			for(i=1; i<n; i++){
				for(j=(i+1); j<n; j++){
					for(k=(j+1); k <= n; k++){
						comp = x - (i + j);
						if (k == comp){
							result++;
						}
					}
				}
			}
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 26248
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto A = aryread();
    auto ans = new long[][](2, N + 1);
    ans[0][0 .. N][] = A[];
    foreach (i; 0 .. K)
    {
        ans[(i + 1) & 1][] = 0;
        foreach (j; 0 .. N)
        {
            ans[(i + 1) & 1][max(0, j - ans[i & 1][j])] += 1;
            ans[(i + 1) & 1][min(j + ans[i & 1][j] + 1, N)] += -1;
        }
        bool allN = true;
        foreach (j; 0 .. N)
        {
            allN = allN && ans[(i + 1) & 1][j] == N;
            ans[(i + 1) & 1][j + 1] += ans[(i + 1) & 1][j];
        }
        if (allN)
        {
            // writeln(i);
            arywrite(ans[(i + 1) & 1][0 .. N]);
            return;
        }
    }
    arywrite(ans[K & 1][0 .. N]);
}


Measured memory_bytes: 16380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<vector<int>> vvi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)

const int INF = INT_MAX;

int fact[9]; 

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;cin>>n;
	int** dp = new int*[3];
	rep(i,0,2) dp[i] = new int[n+1];
	dp[0][0]=0; dp[1][0]=0; dp[2][0]=0;

	rep(day,1,n){
		rep(i,0,2){
			int x;cin>>x;
			if(i==0) dp[0][day] = x+max(dp[1][day-1],dp[2][day-1]);
			else if(i==1) dp[1][day] = x+max(dp[0][day-1],dp[2][day-1]);
			else dp[2][day] = x+max(dp[0][day-1],dp[1][day-1]);
		}
	}

	int ans = dp[0][n];
	rep(i,1,2) ans=max(ans,dp[i][n]);
	cout << ans;

	rep(i,0,2) delete[] dp[i];
	delete[] dp;
	
	return 0;
	
}

Measured memory_bytes: 1408
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cerr<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=998244353;
const int inf=1e9+7;
const double eps=1e-6;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
const double pi=acos(-1);

int cnt[304050];
vector<int> h[304050];
multiset<int> s;

void add(int x){
    auto p=s.find(cnt[x]);
    s.erase(p);
    cnt[x]++;
    s.insert(cnt[x]);
}

void del(int x){
    auto p=s.find(cnt[x]);
    s.erase(p);
    cnt[x]--;
    s.insert(cnt[x]);
}

int main(){
    TB
    int n,m,q,ans=0;
    cin>>n>>m>>q;
    fd(q){
        int x,y;
        cin>>x>>y;
        h[x].push_back(y);
        cnt[y]++;
    }
    for(int i=0;i<=m;i++) s.insert(cnt[i]);
    for(int i=1;i<=n;i++){
        int res=(int)h[i].size();
        for(int j=0;j<h[i].size();j++){
            del(h[i][j]);
        }
        ans=max(ans,res+(int)(*s.rbegin()));
        for(int j=0;j<h[i].size();j++){
            add(h[i][j]);
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 35356
#include <stdio.h>
int main(void) {
	int a, b, c, d, w, x, y, z, s, t;
	scanf("%d %d %d %d %d %d %d %d",&a,&b,&c,&d,&w,&x,&y,&z);
	s = a + b + c + d;
	t = w + x + y + z;
	if(s < t)
		printf("%d\n",t);
	else
		printf("%d\n",s);
	
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll ans=1;ll n;ll a[100008];
ll mod=998244353;
int main()
{
	scanf("%lld",&n);for(int i=1;i<=n;i++) scanf("%lld",&a[i]);sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) ans=ans*__gcd(a[i],(ll)i-1)%mod;printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;
 
int32_t main(){
	int n, k;
	cin >> n >> k;
	map<int,int> m;
	
	for(int i = 0; i < k; i++){
		int x;
		cin >> x;
		for(int j = 0; j < x; j++){
			int p;
			cin >> p;
			m[p]++;
		}
	}
	cout << n - m.size() << endl;
 
	return 0;
}
 

Measured memory_bytes: 3644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author ilyakor
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA {

    public void solve(int testNumber, InputReader in, OutputWriter out) {
      long x = in.nextLong();
      long y = in.nextLong();
      if (x % y == 0) {
        out.printLine(-1);
        return;
      }
      out.printLine(x);
    }

  }

  static class InputReader {

    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public static boolean isSpace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int read() {
      if (count == -1) {
        throw new InputMismatchException();
      }
      try {
        if (cur >= count) {
          cur = 0;
          count = stream.read(buffer);
          if (count <= 0) {
            return -1;
          }
        }
      } catch (IOException e) {
        throw new InputMismatchException();
      }
      return buffer[cur++];
    }

    public int readSkipSpace() {
      int c;
      do {
        c = read();
      } while (isSpace(c));
      return c;
    }

    public long nextLong() {
      long sgn = 1;
      int c = readSkipSpace();
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      long res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res = res * 10L + (long) (c - '0');
        c = read();
      } while (!isSpace(c));
      res *= sgn;
      return res;
    }

  }

  static class OutputWriter {

    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void printLine(Object... objects) {
      print(objects);
      writer.println();
    }

    public void close() {
      writer.close();
    }

  }
}



Measured memory_bytes: 21460
import math
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
cnt = [0] * 10001
r_n = int(math.sqrt(n)) + 1
for x in range(1, r_n):
    for y in range(1, r_n):
        for z in range(1, r_n):
            v = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if v <= n:
                cnt[v] += 1

for i in range(1, n + 1):
    print(cnt[i])


Measured memory_bytes: 9340
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>

using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using intpv=vector<intpair>;
using llpair=pair<ll,ll>;
using llpv=vector<llpair>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;
using pairmat=vector<llpv>;

template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())
#define matin(mat,H,W) for(int i__=0; i__<H; i__++)for(int j__=0; j__<W; j__++) cin>>mat[i__][j__]
#define out(n) cout<<n<<endl

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

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

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a__: v) cin>>a__;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a__: v) cin>>a__;
}

template<class N> void resiz(N n) {} // empty
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll GCD(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}

ll Fact(ll x, ll p) { //階乗
	ll f=1;
	for(ll i=2; i<=x; i++) {
		f*=i;
		f%=p;
	}
	return f;
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll div=1LL;
	while(n/div) {
		digit++;
		div*=10;
	}
	return digit;
}


int A,B;

void input() {
	cin>>A>>B;
}

void solve() {
	cout<<A*B<<endl;
}

int main() {
	while(1) {
		input();
		solve();
		break;
	}
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define mod 1000000007

using namespace std;
class CompareFirst
{
public:
  bool operator()(pair<int,int> n1,pair<int,int> n2) {
    return n1.first>n2.first; //>:desc <:asc
  }
};

int main(){
  string s,t,ss;
  int a,b,i,j,l,m=0;
  unsigned long long n,k,ans;
  vector<string> vs;
  vector<int> v[26];
  pair<int,int> pr;
  //unordered_map<string,int> mp;
  //priority_queue<int> pq; // default ‘å‚«‚¢‡
  //priority_queue<pair<int,int>,vector<pair<int,int>>,CompareFirst> pq

  cin >> n;
  n--;
 // k = 0.5*n;
  if(n%2==0){
    k=n/2;
    ans = k*(n+1);
  }else{
    k=(n+1)/2;
    ans = n*k;
  }
 // ans = 0.5*n*(n+1);
  
 
  cout << ans << endl;
  return 0;

}

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

total = 0
for i in range(n):
  if a[i] >= b[i]:
    total += b[i]
  elif a[i] + a[i+1] >= b[i]:
    total += b[i]
    a[i+1] -= b[i] - a[i]
  else:
    total += a[i] + a[i+1]
    a[i+1] = 0
    
print(total)

Measured memory_bytes: 19116
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(;;){
			int n=sc.nextInt();
			if(n==0)
				break;
			int[] s=new int[n];
			int[] c=new int[n];
			for(int i=0; i<n; i++)
				s[i]=sc.nextInt();
			for(int op=0;; op++){
				for(int j=0; j<n; j++){
					int cnt=0;
					for(int i=0; i<n; i++)
						if(s[i]==s[j])
							cnt++;
					c[j]=cnt;
				}
				boolean f=true;
				for(int i=0; i<n; i++)
					if(s[i]!=c[i])
						f=false;
				if(f){
					println(op+"");
					for(int i=0; i<n; i++)
						print(s[i]+(i==n-1?"":" "));
					println("");
					break;
				}
				System.arraycopy(c, 0, s, 0, n);
			}
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

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

struct edge{
	int to, cost;
};

vector<edge> G[100000];
int N;
int used[100000], color[100000];

void dfs(int v, int c){
	color[v] = c;
	used[v] = 1;
	for(int i=0; i<G[v].size(); i++){
		if(used[G[v][i].to] == 0){
			edge e = G[v][i];
			if(e.cost % 2 != 0){
				dfs(e.to, (c+1)%2);
			}else{
				dfs(e.to, c);
			}
		}
	}
}

int main(){
	cin >> N;
	for(int i=0; i<N-1; i++){
		int v, u, w;
		cin >> v >> u >> w;
		v--; u--;
		edge e1 = {u, w};
		edge e2 = {v, w};
		G[v].push_back(edge{u, w});
		G[u].push_back(edge{v, w});
	}
	dfs(0, 0);
	for(int i=0; i<N; i++){
		cout << color[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int n, a[3][3], b[3][3], k = 0, c;
    rep(i, 3) rep(j, 3) {
        b[i][j] = 0;
        cin >> a[i][j];
    }
    cin >> n;
    rep(i, n) {
        cin >> c;
        rep(i, 3) {
            rep(j, 3) {
                if (c == a[i][j])
                    b[i][j] = 1;
            }
        }
    }
    rep(i, 3) {
        if (b[i][1] && b[i][2] && b[i][0]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    rep(i, 3) {
        if (b[0][i] && b[1][i] && b[2][i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (b[0][0] && b[1][1] && b[2][2])
        cout << "Yes" << endl;
    else if (b[0][2] && b[1][1] && b[2][0])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)


//ABC080_b
int main() {
	string N;
	cin >> N;

	int len = N.size();

	int sum = 0;
	rep(i, len) {
		int a = N.at(i) - '0';
		sum += a;
	}
	if (stoi(N) % sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main() {
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<algorithm>
int x[110][110];
int y[110][110];
int v[110][110];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++)
				scanf("%d%d",&y[i][j],&x[i][j]);
		int ret=0;
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++)
				v[i][j]=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				int row=i;
				int col=j;
				int s,t;

				while(!v[row][col]){
					v[row][col]=1;
					s=x[row][col];
					t=y[row][col];
					row=s;col=t;
				}
				if(v[row][col]==1)ret++;
				row=i;col=j;
				while(v[row][col]!=2){
					v[row][col]=2;
					s=x[row][col];
					t=y[row][col];
					row=s;col=t;
				}
			}
		}
		printf("%d\n",ret);
	}
}

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

using namespace std;

int main(void){
    int N;
    vector<int> W; 

    cin>>N;
    W.resize(N+1);
    for(int i=1; i<N+1; i++){
        cin>>W[i];
    }

    vector<int> S;
    S.resize(N+1);
    for(int i=2; i<=N+1; i++){
        int s=0;
        for(int j=1; j<i; j++){
            s+=W[j];
        }
        S[i-1] = s;
    }

    int m = 1000000000;
    for(int i=1; i<N+1; i++){
        if(abs(S[i] - (S[N]-S[i])) <= m){
            m = abs(S[i] - (S[N]-S[i]));
        }
    }
    cout<<m<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
int main()
{
   ll x,k,d;
   cin>>x>>k>>d;
   x=abs(x);
   ll p=x/d;
   if(x%d>=d/2)
   p++;
   if(k>=p)
   k-=p;
   else
   {
       cout<<abs(x-k*d)<<endl;
       return 0;
   }
   if(k%2==0)
   cout<<abs(x-p*d)<<endl;
   else
   {
       ll iu=(x-p*d);
       cout<<min(abs(iu-d),abs(iu+d))<<endl;
   }
   
   

}

Measured memory_bytes: 3672
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//みなさん天才的ですよね

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;

}
int KH[300001], KW[300001];
int h[300001], w[300001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H = getint(), W = getint(), M = getint();

	rep(i, M) {
		KH[h[i] = getint()]++;
		KW[w[i] = getint()]++;
	}

	int saidaih = -1, hh = 0;
	rep1(i, H) {
		if (saidaih < KH[i]) {
			saidaih = KH[i];
			hh = 1;
		}
		else if (saidaih == KH[i]) hh++;
	}
	int saidaiw = -1, ww = 0;
	rep1(i, W) {
		if (saidaiw < KW[i]) {
			saidaiw = KW[i];
			ww = 1;
		}
		else if (saidaiw == KW[i]) ww++;
	}

	ll are = ll(hh) * ww;

	int kazu = 0;
	rep(i, M) {
		kazu += (KH[h[i]] == saidaih && KW[w[i]] == saidaiw);
	}

	printf("%d\n", saidaih + saidaiw - (kazu == are));

	Would you please return 0;
}

Measured memory_bytes: 6408
import collections

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

L = collections.Counter(map(lambda x: x[0] + x[1] + 1, enumerate(A)))
R = collections.Counter(map(lambda x: x[0] - x[1] + 1, enumerate(A)))

res = 0
for i in range(2, N):
    res += L.get(i, 0) * R.get(i, 0)
print(res)


Measured memory_bytes: 59720
#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;

template <typename Iterator> bool next_combination(const Iterator first, Iterator k, const Iterator last);

int main() {
	u64 N, M, Q;
	cin >> N >> M >> Q;
	
	vector<u64> a(Q);
	vector<u64> b(Q);
	vector<u64> c(Q);
	vector<u64> d(Q);
	for(u64 i=0; i<Q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];	
	
	vector<u64> A(M * N);
	for(u64 i=0; i<M; i++) {
		for(u64 j=0; j<N; j++) {
			A[i * N + j] = i;
		}
	}
		
	u64 ans = 0;
	
	do{
		//for(u64 i=0; i<N; i++) cout << A[i] << " ";
		//cout << endl;
			
		u64 tans = 0;
        for(u64 i=0; i<Q; i++) {
			if(A[b[i]-1] == A[a[i]-1] + c[i]) {
				tans += d[i];
			}
		}
		
		ans = max(ans, tans);
		
    }while(next_combination(A.begin(), A.begin() + N, A.end()));
	
	cout << ans;
	
	return 0;
}

template <typename Iterator> bool next_combination(const Iterator first, Iterator k, const Iterator last) {
	if((first == last) || (first == k) || (last == k)) return false;
	
	Iterator itr1 = first;
	Iterator itr2 = last;
	
	++itr1;
	
	if(last == itr1) return false;
	
	itr1 = last;
	--itr1;
	itr1 = k;
	--itr2;
	
	while(first != itr1) {
		if(*--itr1 < *itr2) {
			Iterator j = k;
			
			while(!(*itr1 < *j)) ++j;
			
			iter_swap(itr1,j);
			
			++itr1;
			++j;
			itr2 = k;
			
			rotate(itr1,j,last);
			
			while(last != j) {
				++j;
				++itr2;
			}
			
			rotate(k,itr2,last);
			return true;
		}
	}
	
	rotate(first,k,last);
	return false;
}

Measured memory_bytes: 3612
#include <cstdio>

int N;
long long L[87];

int main(){
    scanf("%d", &N);
    L[0] = 2LL;
    L[1] = 1LL;
    for (int i = 2; i <= N; i++)
        L[i] = L[i-2] + L[i-1];
    printf("%llu\n", L[N]);
    return 0;
}

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

int main(){
	long n;
	cin >> n;
	for (long i = 0; i < n; i++){
		vector<long> edge(3);
		cin >> edge[0] >> edge[1] >> edge[2];
		sort(edge.begin(), edge.end());
		if (edge[0] * edge[0] + edge[1] * edge[1] == edge[2] * edge[2]){
			cout << "YES" << endl;
		} 
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}




int main() {
  int n;
  cin >> n;
  vi a(n);
  vi m(pow(10,6),0);
  REP(i,n) {
    cin >> a[i];
    m[a[i]]++;
  }
  int ans=0;
  REP(i,n) {
    int temp=0;
    temp+=m[a[i]]+m[a[i]+1]+m[a[i]-1];
    ans=max(ans,temp);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int s;
  cin >> s;
  int k=0;
  if(s/100 ==1){
    k++;
  }
  if(s%10 == 1){
    k++;
  }
  if((s%100)/10 ==1){
    k++;
  }
  
  cout << k << endl;

}

Measured memory_bytes: 3592
N = int(input())
C=[list(map(int,input().split())) for _ in range(N)]

A=[]
B=[]
for i in range(N):
    A.append(C[i][0])
    B.append(C[i][1])

A.sort()
B.sort()

if N%2==0:
    mA = (A[N//2-1]+A[N//2])
    mB = (B[N//2-1]+B[N//2])
else:
    mA = A[N//2]
    mB = B[N//2]

print(mB-mA+1)

Measured memory_bytes: 49376
def f(i):
    if i == w - 1:
        for j in range(w - 2):
            if s[j] == s[j + 1] == 1:
                return
        global x
        for j in range(w):
            if j == 0:
                if s[0] == 1:
                    x[0][1] += 1
                else:
                    x[0][0] += 1
            elif j == w - 1:
                if s[w - 2] == 1:
                    x[w - 1][w - 2] += 1
                else:
                    x[w - 1][w - 1] += 1
            else:
                if s[j - 1] == 1:
                    x[j][j - 1] += 1
                elif s[j] == 1:
                    x[j][j + 1] += 1
                else:
                    x[j][j] += 1 
        return
    s[i] = 1
    f(i + 1)
    s[i] = 0
    f(i + 1)

h, w, k = map(int, input().split())
mod = pow(10, 9) + 7
s = [0] * (w - 1)
x = [[0] * w for _ in range(w)]
if not w == 1:
    f(0)
else:
    print(1)
    exit()
dp = [[0] * w for _ in range(h + 1)]
dp[0][0] = 1
for i in range(1, h + 1):
    for j in range(w):
        for l in range(w):
            dp[i][j] += dp[i - 1][l] * x[l][j]
            dp[i][j] %= mod
print(dp[h][k - 1])

Measured memory_bytes: 9316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int,P> P3;
typedef pair<double, P3> P4;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(3e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, ans=0;
    vector<P> ls[35];
    bool used[105]{};
    cin >> n;
    REP(i,n){
        int a, b;
        cin >> a >> b;
        ls[a].push_back({b,i});
    }
    priority_queue<P, vector<P>, greater<P> > que;
    for(int i=1;i<=31;i++){
        for(auto p : ls[i]) que.push(p);
        while(!que.empty() && que.top().first < i)que.pop();
        if(!que.empty()){
            ans += 100;
            que.pop();
        }
        else ans += 50;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3072
use proconio::{input, marker::Chars};

macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        s: Chars,
    }

    const MOD: usize = 2019;
    let mut dp = vec![0usize; MOD];
    dp[0] = 1;
    let mut pow = 1;
    let mut now = 0;
    let mut ans = 0;

    for digit in s.iter().rev() {
        let digit = digit.to_digit(10).unwrap() as usize;
        now = (now + pow * digit) % MOD;
        ans += dp[now];
        dp[now] += 1;
        pow = 10 * pow % MOD;
    }

    echo!(ans);
}


Measured memory_bytes: 2944
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 309;
int n, Mx, A[N];
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n + n; i ++)
        scanf("%d", &A[i]);
    sort(A, A + n + n);
    for (int i = 0; i < n + n; i += 2)
        Mx += A[i];
    return !printf("%d\n", Mx);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int a, b;
int x, y, t;

int main () {
    cin >> a >> x;
    cin >> b >> y;
    cin >> t;
    if (x <= y) return !printf("NO");
    int dif = (abs(a - b));
    int speed_dif = abs(x - y);
    if (dif  <= 1LL * t * speed_dif) {
        return !printf("YES");
    } else printf("NO");
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3660