akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
const ll inf = 1000000000000000000;
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vector<ll> v(n);
    rep(i,n)cin >> v[i];
    sort(v.begin(),v.end());
    ll l = -inf, r = inf+1ll;//[l, r)で二分探索
    while(1<r-l){
        ll med = (l+r)/2;
        ll cnt = 0;
        rep(i,n){
            if (v[i] < 0){
                int left = -1, right = n;
                while (right-left > 1){
                    int x = (right+left)/2;
                    if (v[x]*v[i] < med) right = x;
                    else left = x;
                }
                cnt += n-right;
            }
            else {
                int left = -1, right = n;
                while(right-left > 1){
                    int x = (right+left)/2;
                    if (v[x]*v[i] < med) left = x;
                    else right = x;
                }
                cnt += right;
            }
            if (v[i]*v[i] < med)cnt--;
        }
        cnt /= 2;
        if (cnt < k) l = med;
        else r = med;
    }
    cout << l << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
  	int N, A, B;
  	scanf("%d", &N);
  	if (N == 2) {
   		scanf("%d %d", &A, &B);
  		printf("%d", A + B);
    }
  	else
      	puts("Hello World");
  	return 0;
}

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

int main() {
    uint N;
    cin >> N;
    set<int> s;
    for (size_t i=0; i<N; ++i) {
        int a;
        cin >> a;
        s.insert(a);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 3624
// Many Requirements

class RepeatedCombination<T>: Sequence, IteratorProtocol {
    var state: Array<Int>?
    
    func next() -> Array<T>? {
        var ret: Array<T> = []
        guard let currentState = self.state else {
            return nil
        }
        for index in currentState {
            ret.append(baseArray[index])
        }
        self.state = nextState()
        return ret
    }
    
    private func nextState() -> Array<Int>? {
        guard var currentState = self.state else {
            return nil
        }
        for i in 0..<self.takes {
            if currentState[takes-i-1] != self.n - 1 {
                let n = currentState[takes-i-1] + 1
                for j in (takes-i-1)..<self.takes {
                    currentState[j] = n
                }
                return currentState
            }
        }
        return nil
    }
    
    typealias Element = Array<T>
    
    let baseArray: Array<T>
    let takes: Int
    let n: Int
    
    
    init(_ baseArray: Array<T>, _ takes: Int){
        self.baseArray = baseArray
        self.takes = takes
        self.n = baseArray.count
        self.state = Array<Int>(repeating: 0, count: takes)
    }
}


func main() {
    let nmq = readLine()!.split(separator: " ").map{Int($0)!}
    let (n,m,q) = (nmq[0], nmq[1], nmq[2])
    var abcd: [[Int]] = []
    for _ in 1...q {
        abcd.append(readLine()!.split(separator: " ").map{Int($0)!})
    }
    let arr = Array(1...m)
    let rcombi = RepeatedCombination(arr, n)
    // Aの候補を全部試す
    var max = 0
    for ar in rcombi {
        // 得点計算
        var score = 0
        for i in 0..<q {
            let abcdi = abcd[i]
            let (ai, bi, ci, di) = (abcdi[0], abcdi[1], abcdi[2], abcdi[3])
            if ar[bi-1] - ar[ai-1] == ci {
                score += di
            }
        }
        if score > max {
            max = score
        }
    }
    print(max)
}

main()

Measured memory_bytes: 8336
import java.util.*;

public class Main{

    int n,m;
    char[] c;
    int[][] dp;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            if(n==0) break;
            m = sc.nextInt();
            c = sc.next().toCharArray();

            int idx = 0;
            while(c[idx]!='I') idx++;

            int ans = 0;
            int num = n*2+1;
            for(int i=idx; i<c.length; i++){
                if(i==c.length-1){
                    if(c[i]=='O'){
                        if(i-idx+1>=num) ans += (i-idx+1-num)/2+1;
                    }else{
                        if(i-idx+1>=num) ans += (i-idx+1-num)/2+1;
                    }
                }else if(c[i]=='O' && c[i+1]=='O'){
                    if(i-idx+1>=num) ans += (i-idx+1-num)/2+1;
                    idx = i;
                    while(idx<c.length && c[idx]!='I') idx++;
                    i = idx-1;
                }else if(c[i]=='I' && c[i+1]=='I'){
                    if(i-idx+1>=num) ans += (i-idx+1-num)/2+1;
                    idx = i+1;
                    i = idx-1;
                }
            }

            System.out.println(ans);
        }
    }

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

Measured memory_bytes: 18000
# include <stdio.h>
int main()
{
  int n,m;
  scanf("%d %d",&n,&m);
  int e[n];
  for(int i=0;i<n;i++)
    scanf("%d",&e[i]);
  int l[n];
  for(int i=0;i<n;i++)
    l[i]=1;
  for(int i=0;i<m;i++)
  {
    int a,b;
    scanf("%d %d",&a,&b);
    if(e[a-1]<=e[b-1])
      l[a-1]=0;
    if(e[b-1]<=e[a-1])
       l[b-1]=0;
       }
    int ctr=0;
       for(int i=0;i<n;i++)
       {
         if(l[i]==1)
           ctr++;
       }
       printf("%d",ctr);
       return 0;
       }

Measured memory_bytes: 2472
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	
	int n,p;
	
	bool is_prime[103000];
	int prime_list[10000];
	int sum_list[10000];
	int num_of_prime = 0;
	for(int i=0;i<sizeof(is_prime)/sizeof(bool);i++){
		if(i<2){
			is_prime[i] = false;
			continue;
		}
		is_prime[i] = true;
		int j;
		for(j=0;j<num_of_prime;j++){
			if(i % prime_list[j] == 0){
				break;
			}
		}
		if(j!= num_of_prime){
			is_prime[i] = false;
		}else{
			prime_list[num_of_prime] = i;
			num_of_prime ++;
		}
	}
	
	while(1){
		scanf(" %d %d", &n, &p);
		
		if(n ==-1 && p == -1){
			break;
		}
		int i;
		for(i=0;i<num_of_prime;i++){
			if(prime_list[i] > n){
				break;
			}
		}
		
		int cnt = 0;
		for(int j=0;j<100;j++){
			for(int k=j;k<100;k++){
				sum_list[cnt] = prime_list[i + j] + prime_list[i + k];
				cnt ++;
			}
		}
		sort(sum_list,sum_list+cnt);
		printf("%d\n", sum_list[p-1]);
		
	}
	
	return 0;
}

Measured memory_bytes: 1104
import sys
readline = sys.stdin.readline

x, y, z, k = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
c = list(map(int, readline().split()))

a.sort(); a.reverse()
b.sort(); b.reverse()
c.sort(); c.reverse()

added = [[0,0,0]]
heap = [[a[0]+b[0]+c[0],0,0,0]]
n = 1

def print_heap(heap):
	m=0
	while m<len(heap):
		m2=m*2+1
		print(heap[m:min(m2,len(heap))])
		m=m2

def upheap(heap,n):
	i = n-1
	while i > 0:
		parent = (i-1)//2
		if heap[i][0] > heap[parent][0]:
			tmp = heap[parent]
			heap[parent] = heap[i]
			heap[i] = tmp
			i = parent
		else:
			break
	#print("up", n)
	#print_heap(heap)

def downheap(heap, n):
	if n <= 1:
		heap.pop()
		n -= 1
	else:
		heap[0] = heap.pop()
		n -= 1
		i = 0
		while True:
			child = 2 * i + 1
			if child > n-1:
				break
			if child < n-1 and heap[child][0] < heap[child+1][0]:
				child += 1
			if heap[i][0] < heap[child][0]:
				tmp = heap[child]
				heap[child] = heap[i]
				heap[i] = tmp
				i = child
			else:
				break
	#print("down", n)
	#print_heap(heap)
	return n

for _ in range(k):
	#print(n, heap)
	v, pa, pb, pc = map(int, heap[0])
	print(v)
	n = downheap(heap, n)
	if pa+1 < x and not [pa+1, pb, pc] in added:
		added.append([pa+1, pb, pc])
		n += 1
		heap.append([a[pa+1] + b[pb] + c[pc], pa+1, pb, pc])
		upheap(heap, n)
	if pb+1 < y and not [pa, pb+1, pc] in added:
		added.append([pa, pb+1, pc])
		n += 1
		heap.append([a[pa] + b[pb+1] + c[pc], pa, pb+1, pc])
		upheap(heap, n)
	if pc+1 < z and not [pa, pb, pc+1] in added:
		added.append([pa, pb, pc+1])
		n += 1
		heap.append([a[pa] + b[pb] + c[pc+1], pa, pb, pc+1])
		upheap(heap, n)


Measured memory_bytes: 4704
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables
#define ZINDA cerr<<"\nIdhar-ich hai apun!!\n"; //to debug if code reached that point
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define mkp make_pair
#define pb push_back
#define endl '\n'
#define mod 1000000007
 
typedef long long int lld;
typedef unsigned long long int ulld;
 
lld power(lld b, lld e)
{
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n<0) 
		n*=-1;
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

void swagWaalaFunction()
{
	lld n,m,ai=0,sum=0;
	cin>>n>>m;

	lld arr[n];
	FORZ(i,n)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	FORZ(i,n)
	{
		if(1.0*arr[i]>=sum*pow(4*m,-1))
			ai++;
	}

	// cerr<<ai;
	if(ai>=m)
		cout<<"Yes";
	else
		cout<<"No";
	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	while(t--)
 		swagWaalaFunction();

 	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = Integer.parseInt(sc.next());
        int[] c = new int[a];
        
        int min = Integer.MAX_VALUE;
        int total = 0;
        for(int i = 0;i<a;i++){
            c[i] = sc.nextInt();
            if(c[i]<min){
                min = c[i];
            }
            total += c[i];
        }

        int d = b -total;
        int e = d/min;
        System.out.println(a+e);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
 
int N;
int parent[100001];
int sibling[100001];
int degree[100001];
 
int calcDepth(int i) {
  if(parent[i] == -1) return 0;
  return calcDepth(parent[i]) + 1;
}
 
int calcHeight(int i) {
  int j, h;
  h = 0;
  for(j = 0; j < N; ++j) {
    if(parent[j] == i) {
      int tmp = calcHeight(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}
 
int main() {
  int i,j;
  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    parent[i] = -1;
    sibling[i] = -1;
    degree[i] = 0;
  }
  for(i = 0; i < N; ++i) {
    int id, left, right;
    scanf("%d %d %d", &id, &left, &right);
    if(left != -1) {
      parent[left] = id;
      sibling[left] = right;
      ++degree[id];
    }
    if(right != -1) {
      parent[right] = id;
      sibling[right] = left;
      ++degree[id];
    }
  }
 
  for(i = 0; i < N; ++i) {
    int depth = calcDepth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
           i, parent[i], sibling[i], degree[i], depth, calcHeight(i));
    if(depth == 0) {
      printf("root\n");
    } else if(degree[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1760
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  char x,y;
  cin>>x>>y;
  if(x==y){
    cout<<'='<<"\n";
  }else if(x>y){
    cout<<'>'<<"\n";
  }else{
    cout<<'<'<<"\n";
  }
}


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

	int main(){
      int N,M;
      cin >> N >> M;
      int a[N]={},b[N]={},c[M]={},d[M]={};
      for (int i;i<N;i++){
        cin >> a[i] >> b[i];
      }
      for (int i;i<M;i++){
        cin >> c[i] >> d[i];
      }
      int x,y,z;
      for (int i=0;i<N;i++){
        x=0;
        y=abs(a[i]-c[0])+abs(b[i]-d[0]);
        for (int j=0;j<M;j++){
          z=abs(a[i]-c[j])+abs(b[i]-d[j]);
          if (y>z){
            x=j;
            y=z;
          }
        }
        cout << x+1 << endl;
      }
    }

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


int main() {
  long h,w,k;
  cin>>h>>w>>k;
  vector<vector<char>>a(h,vector<char>(w));
  rep(i,h){
    rep(j,w){
      cin>>a.at(i).at(j);
    }
  }
  int ans=0;
  for (int tmp = 0; tmp < (1 << h); tmp++) {
    bitset<7> s(tmp);
    for (int tm = 0; tm < (1 << w); tm++) {
      bitset<7> t(tm);
    int co=0;
    rep(i,h){
      rep(j,w){
        if(s.test(i)&&t.test(j)&&a[i][j]=='#'){
          co++;
        }
      }
    }
      if(co==k){
        ans++;
      }
    }
      
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 3600
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int Q=1<<20;
int fa[Q];
int in[Q],out[Q];
int gf(int x)
{return fa[x]==x?x:(fa[x]=gf(fa[x]));}
void ins(int x,int y)
{
    out[x]++;
    in[y]++;
    int fx=gf(x),fy=gf(y);
    if(fx!=fy)fa[fx]=fy;
}
// int Idiot_Sap(int x,int flow)
// {
//     if(x==T)return flow;
//     int had=0;
//     for(int t=las[x];t;t=nn[t]){
//         int y=e[t];
//         if((!c[t])||dis[x]-1!=dis[y])continue;
//         int del=Idiot_Sap(y,min(c[t],flow-had));
//         c[t]-=del;
//         c[t^1]+=del;
//         had+=del;
//         if(dis[S]>=T||had==flow)return had;
//     }
//     if(dis[S]>=T)return had;
//     --cnt[dis[x]];
//     if(!cnt[dis[x]])dis[S]=T;
//     cnt[++dis[x]]++;
//     return had;
// }
int had[Q];
int main()
{
    int n,h;
    cin>>n>>h;
    h+=5;
    for(int i=1;i<=h+h;i++)fa[i]=i;
    for(int i=1,a,b,c,d;i<=n;i++){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        ++a,++b,++c,++d;
        int x,y;
        if(c==1)x=a+h;
        else x=c;
        if(d==1)y=b;
        else y=d+h;
        // printf("%d %d LINK\n",x,y);
        ins(x,y);
    }
    for(int i=1;i<=h;i++)if(out[i]>in[i])return puts("NO")&0;
    for(int i=h+1;i<=h+h;i++)if(out[i]<in[i])return puts("NO")&0;
    for(int i=1;i<=h+h;i++)if(in[i]!=out[i])had[gf(i)]=1;
    for(int i=1;i<=h+h;i++)if(in[i]&&out[i]&&(!had[gf(i)]))return puts("NO")&0;
    puts("YES");
    return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = 0;
    for (char c : s) {
        if (c == 'o') {
            n++;
        }
    }
    cout << 700 + n * 100;
}


Measured memory_bytes: 3600
a,b=map(int,input().split())
c=[]
for i in range(a):
    d=list(map(int,input().split()))
    c.append(d)


ans=0
for j in range(a):
    for k in range(j+1,a):
        count=0
        sum=0
        for l in range(b):
            e=abs(c[j][l]-c[k][l])
            f=e**2
            count +=1
            if count <=b:
                sum +=f
                
        for n in range(sum+1):
            if n**2 == sum:
                ans +=1
                
print(ans)    

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

const int N = 100;

int main() {
    using namespace std;
    int n, k, x[N];
    int i;

    cin >> n >> k;

    int sum = 0;
    for (i=0; i<n; ++i) {
        cin >> x[i];
        sum += 2 * min(x[i], k-x[i]);
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int N,M;
  cin>>N>>M;
  
  vector<long long int>X(M);
  vector<long long int>sub(M);
  sub[0]=0;
 
  
  for(long long int i=0;i<M;i++){
    cin>>X[i];
  }
  
  sort(X.begin(),X.end());
  
  for(long long int i=1;i<M;i++){
    sub[i]=abs(X[i]-X[i-1]);
  }

    
  
  sort(sub.begin(),sub.end());
  
 long long int sum=0;
  
  for(long long int i=1;i<M-N+1;i++){
    sum+=sub[i];
  }
  
  cout<<sum<<endl;
}
  
  

Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());

        // 主処理
        int noHalf = a * x + b * y;

        int min = Math.min(x, y);
        int numC = c * min * 2;
        int remain = x <= y ? (y - min) * b : (x - min) * a;
        int inHalf = numC + remain;

        int allHalf = c * Math.max(x, y) * 2;

        int result = Math.min(Math.min(noHalf, inHalf), allHalf);

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23764
/*	ex3_4
	suzuto	*/

#include <stdio.h>

int main(void) {
  int divident, divisor, quotient, det; /*変数の宣言*/

  scanf("%d",&divident); /*Nの入力*/
  divisor = 1; /*divisorの初期化*/
  det = 0; /*detの初期化*/

  /*divident = divisor * quotientとなる(1以上9以下の積で表せる)かどうかを調べる*/
  while(divisor <= 9){
    quotient = (divident / divisor) % 10; /*商quotientの一の位を算出する(quotient二桁以上の時必ずdivident > divisor * quotient)*/
    if(divident == divisor * quotient){
      det = 1; /*積として表すことができたことを記憶する*/
      printf("Yes\n");
      break;
    }
    divisor++; /*divisorの更新*/
  }
  if (det == 0){
    printf("No\n"); /*積で表せなかった(det初期値のまま)のでNoを出力*/
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
int a[200004];
int main(){
	int n,k;cin>>n>>k;
	for (int i=1;i<=n;i++) cin>>a[i];sort(a+1,a+1+n);
	for (int i=1;i<=n-k;i++) ans+=a[i];cout<<ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

int main(){
    int N;cin>>N;
    vl A(N+1), B(N);
    REP(i, N+1){
        cin>>A[i];
    }
    REP(i, N){
        cin>>B[i];
    }

    ll ans = 0l;
    ll rem = A[0];
    REP(i, N){
        if(rem >= B[i]){
            ans += B[i];
            rem = A[i+1];
        }else if(B[i] - rem <= A[i+1]){
            ans += B[i];
            rem = A[i+1] - (B[i] - rem);
        }else{
            ans += rem + A[i+1];
            rem = 0l;
        }
    }

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

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main {

	void submit() {
		String ss = nextToken();
		char[] s = ss.toCharArray();
		
		int n = s.length;
		
		int ptr = 0;
		
		int[] notX = new int[n];
		
		for (int i = 0; i < n; i++) {
			if (s[i] != 'x') {
				notX[ptr++] = i;
			}
		}
		
		notX = Arrays.copyOf(notX, ptr);
		
		for (int i = 0, j = ptr - 1; i < j; i++, j--) {
			if (s[notX[i]] != s[notX[j]]) {
				out.println(-1);
				return;
			}
		}
		
		if (ptr == 0) {
			out.println(0);
			return;
		}
		
		String one, two;
		if (ptr % 2 == 0) {
			one = ss.substring(0, notX[ptr / 2 - 1]);
			two = reverse(ss.substring(notX[ptr / 2] + 1));
		} else {
			one = ss.substring(0, notX[ptr / 2]);
			two = reverse(ss.substring(notX[ptr / 2] + 1));
		}
		
		out.println(go(one, two));
	}
	
	int go(String one, String two) {
		one += "z";
		two += "z";
		int ret = 0;
		List<Integer> lOne = go(one);
		List<Integer> lTwo = go(two);
		for (int i = 0; i < lOne.size(); i++) {
			ret += Math.abs(lOne.get(i) - lTwo.get(i));
		}
		return ret;
	}
	
	List<Integer> go(String s) {
		List<Integer> ret = new ArrayList<>();
		int cur = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'x') {
				cur++;
			} else {
				ret.add(cur);
				cur = 0;
			}
		}
		return ret;
	}
	
	String reverse(String s) {
		return new StringBuilder(s).reverse().toString();
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


Measured memory_bytes: 27092
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, m;
    cin >> n >> m;
    ll x = 1 << m;
    ll ans = x * (100 * (n - m) + 1900 * m);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {


  val n = readInt()
  val X = readLine().split(" ").map(_.toInt)

  def solve() = {
    (X.min to X.max).foldLeft(Long.MaxValue) { (minConsumption, p) =>
      val consumption = X.foldLeft(0) { (acc, x) =>
        acc + (x-p) * (x-p)
      }
      Math.min(minConsumption, consumption)
    }
  }

  println(solve())

}



Measured memory_bytes: 54920
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

vector<int> C[1<<18];
int N,A[1<<18],R[1<<18];

int main()
{
	scanf ("%d",&N);
	for (int i=0;i<(1<<N);i++){
		scanf ("%d",&A[i]);

		set<int> chk;
		chk.insert(i);
		for (int j=0;j<N;j++) if (i & (1 << j)){
			for (auto x : C[i-(1<<j)]) chk.insert(x);
		}

		C[i] = vector<int>(chk.begin(),chk.end());
		sort(C[i].begin(),C[i].end(),[](const int &a, const int &b){return A[a] > A[b];});
		if (C[i].size() > 2) C[i].resize(2);
	}

	for (int i=1;i<(1<<N);i++){
		R[i] = A[C[i][0]] + A[C[i][1]];
		if (R[i] < R[i-1])
			R[i] = R[i-1];

		printf ("%d\n",R[i]);
	}

	return 0;
}

Measured memory_bytes: 32640
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

minw = min(w)
for i in range(N):
    w[i] -= minw

ww = [[] for _ in range(4)]
for i, o in enumerate(w):
    ww[o].append(v[i])
for i in range(4):
    ww[i].sort(reverse=True)

ans = 0
for i in range(len(ww[0])+1):
    isum = sum(ww[0][:i])
    for j in range(len(ww[1])+1):
        jsum = sum(ww[1][:j])
        for k in range(len(ww[2])+1):
            ksum = sum(ww[2][:k])
            for t in range(len(ww[3])+1):
                tsum = sum(ww[3][:t])
                weight = minw * i + (minw+1) * j + (minw+2) * k + (minw+3) * t
                if weight <= W:
                    ans = max(ans, isum+jsum+ksum+tsum)
print(ans)


Measured memory_bytes: 69548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */
 
int main(void){ 
    int n,k;
    cin >> n >> k;
    vector<int> v;
    for(int i=0; i<n; i++){
        int tmp_v;
        cin >> tmp_v;
        v.push_back(tmp_v);
    }
 
    int ans = 0;
    for(int a=0; a<=min(n,k); a++){
        for(int b=0; b<=min(n-a,k-a); b++){
            vector<int> get;
            int tmp_ans = 0;
 
            for(int i=0; i<a; i++){
                tmp_ans += v[i];
                get.push_back(v[i]);
            }
            for(int i=1; i<=b; i++){
                tmp_ans += v[n-i];
                get.push_back(v[n-i]);
            }
            sort(get.begin(), get.end());


            int size_g = get.size(); // デフォルトの値がlong int(minは型合わせないといけない)

            // ずっとここの場合分けでgetのサイズを無視してた。
            for(int i=0; i < min(size_g, k-(a+b)); i++){
                if(size_g > 0 && get[i] < 0){
                    tmp_ans -= get[i]; 
                }
            }

            if(tmp_ans > ans) ans = tmp_ans;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
    int i,a,b,k;
    cin >> k >> a >> b;
    for(i=a;i<=b;i++){
        if(i%k==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

const ll MOD = 1e9+7;

struct DICE{
    ll num[6];
    ll top;
    ll north,south,west,east;

    DICE(){
        top = 0;
        south = 1;
        east = 2;
        west = 3;
        north = 4;
    }

};


int main(){
    DICE d;
    string s;

    rep(i,0,6){
        cin >> d.num[i];
    }

    cin >> s;

    rep(i,0,s.size()){
        ll tmp;
        switch(s[i]){
            case 'N':
                tmp = d.south;
                d.south = 5 - d.top;
                d.north = d.top;
                d.top = tmp;
                break;
            case 'E':
                tmp = d.west;
                d.west = 5 - d.top;
                d.east = d.top;
                d.top = tmp;
                break;
            case 'S':
                tmp = d.north;
                d.north = 5 - d.top;
                d.south = d.top;
                d.top = tmp;
                break;
            case 'W':
                tmp = d.east;
                d.east = 5 - d.top;
                d.west = d.top;
                d.top = tmp;
                break;
        }
    }

    cout << d.num[d.top] << endl;
    return 0;
}



Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();

        int res = 0;
        for(int i = 0; i < S.length(); i++) {
            if(S.charAt(i) != T.charAt(i)) res++;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 41108
#include <bits/stdc++.h>
using namespace std;
int main(){
	int w, h, n;
	cin>>w>>h>>n;
	int left = 0;
	int right = w;
	int bottom = 0;
	int top = h;
	for(int i = 0; i < n; ++i){
		int x, y, a;
		cin>>x>>y>>a;
		if(a == 1){
			left = max(left, x);
		}
		else if(a == 2){
			right = min(right, x);
		}
		else if(a == 3){
			bottom = max(bottom, y);
		}
		else if(a == 4){
			top = min(top, y);
		}
	}
	int width = right - left;
	int height = top - bottom;
	if(width < 0 || height < 0)cout<<0<<endl;
	else cout<<width * height<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = 1; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i, N) cin >> S[i];
    map<string, int> cnt;
    ll ans = 0;
    rep(i, N) {
        sort(ALL(S[i]));
        ans += cnt[S[i]];
        ++cnt[S[i]];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 13988
Scanf.scanf "%d %d %d" (fun a b k ->
    let rec loop a b r =
        if r = 0 then (if k mod 2 = 0 then Printf.printf "%d %d\n" a b
                                      else Printf.printf "%d %d\n" b a)
        else
            let c = a / 2 in
            loop (b + c) (a / 2 * 2 - c) (r - 1)
    in
    loop a b k
)

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll S, C; cin >> S >> C;

	ll res{0};
	res = min(S, C/2);
	C = max(0ll, C-res*2);
	std::cout << res + C/4 << std::endl;
}

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

int main(){
    int n;
    cin >> n;
    string frag = "Yes";
    int xp = 0; 
    int yp = 0;
    int tp = 0;
    for(int i =0 ; i < n; i++){
        int t,x,y;
        cin >> t >> x >> y;
        if((abs(x) + abs(y)) % 2 != t % 2){
            frag = "No";
        }
        if(abs(x-xp)+abs(y-yp) > t - tp ){
            frag = "No";
        }
        xp = x;
        yp = y;
        tp  =t;
    }
    cout << frag << endl;
}

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

int main(void){
    int n;
    cin>>n;
    vector<int> L(n);
    rep(i,n) cin>>L[i];
    sort(L.begin(),L.end());
    //rep(i,n) cout<<L[i]<<endl;
    long long ans=0;
    rep(i,n){
        for(int j=i+1;j<n;++j){
            int r=lower_bound(L.begin(),L.end(),L[j]+L[i])-L.begin();
            ans+=(r-1)-j;
            //cout<<i<<j<<r<<ans<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ks96neko
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BAcCepted solver = new BAcCepted();
        solver.solve(1, in, out);
        out.close();
    }

    static class BAcCepted {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String r = in.next();
            int rl = r.length();

            String r0 = r.substring(0, 1);
            String a = "A";

            String shortenedString = r.substring(2, rl - 1);
            int c1mojime = shortenedString.indexOf("C");
            int cNmojime = shortenedString.lastIndexOf("C");

            if (!a.equals(r0)) {
                out.println("WA");
                return;
            }
            if (c1mojime == -1) {
                out.println("WA");
                return;
            }
            if (c1mojime != cNmojime) {
                out.println("WA");
                return;
            }
            for (int i = 1; i < rl; i++) {
                if (r.charAt(i) != 'C' && Character.isUpperCase(r.charAt(i))) {
                    out.println("WA");
                    return;
                }
            }
            out.println("AC");
        }

    }
}



Measured memory_bytes: 21972
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
	long long int m[3];
	long long int d, e;
	long long int nn[3];
	while(cin >> m[0] >> m[1] >> m[2] >> d >> e) {
		if (m[0] == 0 && m[1] == 0 && m[2] == 0 && d == 0 && e == 0) {
			break;
		}
		cin >> nn[0] >> nn[1] >> nn[2]; 
		long long int count = m[0]*nn[0]+m[1]*nn[1]+m[2]*nn[2];
		vector<int> v;
		for (int i = 0; i < nn[2]; i++) {
			v.push_back(m[2]);
		}
		for (int i = 0; i < nn[1]; i++) {
			v.push_back(m[1]);
		}
		for (int i = 0; i < nn[0]; i++) {
			v.push_back(m[0]);
		}
		if (d <= nn[2]) {
			count = m[0]*nn[0]+m[1]*nn[1]+e*nn[2];
		} else if (d <= nn[1]+nn[2]){
			count = min(count, min(m[0]*nn[0]+m[1]*(nn[1]-(d-nn[2]))+e*d, m[0]*nn[0]+m[1]*nn[1]+d*e));
		} else if (d <= nn[0]+nn[1]+nn[2]){
			count = min(count, min(m[0]*(nn[0]-(d-nn[2]-nn[1]))+e*d, m[0]*nn[0]+m[1]*nn[1]+d*e));
		} else {
			count = min(count, d*e);
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 4236
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 86029900
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    if (b*c>=a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3608
import math
from sys import exit

n=int(input())
primes = {}
i = 2
ans = 0
square = math.floor(math.sqrt(n))

if n == 1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

primes = factorization(n)

for k,v in primes:
    base = v * 2
    root = math.floor(math.sqrt(base))
    if root * (root + 1) > base:
        root -= 1
    ans += root

print(ans)

Measured memory_bytes: 9516
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
			
		}
public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];

			if (N==1) {
				Console.WriteLine(0);
				return;
			}

			var mod10 = repeatPow(10, N);
			var mod9 = repeatPow(9, N);
			var mod8= repeatPow(8, N);

			var ans = mod10 - 2 * mod9 + mod8;
			while (ans<0) {
				ans += _mod;
			}

			//答えの出力
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
		private static long _mod = 1000000000 + 7;

		/// <summary>
		/// x^n のmod　を繰り返し二乗法で求める
		/// </summary>
		/// <param name="x"></param>
		/// <param name="n"></param>
		/// <returns></returns>
		private static long repeatPow(long x, long n) {
			if (n == 0) {
				return 1;
			}
			if (n == 1) {
				return x;
			}

			if (n % 2 == 1) {
				var a = repeatPow(x, n / 2);
				var b = a * x % _mod;
				return (a * b) % _mod;
			}
			else {
				var a = repeatPow(x, n / 2);
				return (a * a) % _mod;
			}
		}
	}
}


Measured memory_bytes: 28160
#include<cstdio>
using namespace std;
int n,k;
long long ans,cnt;
int main()
{
	scanf("%d%d",&n,&k);
	cnt=(long long)n/(long long)k;
	ans=cnt*cnt*cnt;
	if(!(k%2)) {cnt=0;for(int i=k/2;i<=n;i+=k) cnt++;ans+=cnt*cnt*cnt;}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
//
//  main.cpp
//  B
//
//  Created by 黄宇凡 on 2017/3/12.
//  Copyright © 2017年 黄宇凡. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int maxn = 100000 + 5;

struct creature{
    int color,size;
    creature(int c = 0,int s = 0) : color(c),size(s) {}
    bool operator < (const creature & rhs) const{
        return size < rhs.size;
    }
}c[maxn];

long long sum[maxn];
int main(int argc, const char * argv[]) {
    int n;
    scanf("%d",&n);
    for(int i = 1;i <= n;i++){
        int a;
        scanf("%d",&a);
        c[i].color = i;
        c[i].size = a;
    }
    sort(c + 1,c + 1 + n);
    sum[0] = 0;
    for(int i = 1;i <= n;i++){
        sum[i] = sum[i - 1] + c[i].size;
    }
    int ed = 0;
    for(int i = n - 1;i > 0;i--){
        if(sum[i] * 2 < c[i + 1].size){
            ed = i;
            break;
        }
    }
    cout << n - ed << endl;
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
count = 0
ans = 'No'
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        count += 1
        if count == 3:
            ans = 'Yes'
            break
    else:
        count = 0
print(ans)

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

int main() {
    int a,b,c,d,x=0;
    cin >> a >> b;
    for(int i = a;i < b+1;i ++){
        c = i%100;
        d = c/10 + (c%10)*10;
        if(i / 1000 == d){
            x += 1;
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int b[300000];
int count[300000]={0};
int fa(int k){
	int i=0;
	int a[100000];
	while (b[k]!=k){
		a[i]=k;
		i++;
		k=b[k];
	}
	for (int j=0;j<i;j++){
		b[a[j]]=k;
	}
	return k;
}
int main(){
	int n,m,x,y;
	scanf("%d %d",&n,&m);
	for (int i=1;i<=n;i++){
		b[i]=i;
		count[i]=1;
	}
	for (int i=1;i<=m;i++){
		scanf("%d %d",&x,&y);
		int fax=fa(x);
		int fay=fa(y);
		if (fax==fay) continue;
		b[fax]=fay;
		count[fay]+=count[fax];
	} 
	int ans=0;
	for (int i=1;i<=n;i++){
		if (ans<count[i]) 
		  ans=count[i]; 
	}
	printf("%d",ans);
}


Measured memory_bytes: 3300
# coding: utf-8
import numpy as np

hairetsu = input().split(' ')
sunuke = int(hairetsu[0])
okashi = int(hairetsu[1])
books = [[0]*sunuke]*okashi

for i in range(0, okashi):
  kaisu = int(input())
  whohas = list(map(int, input().split(' ')))
  for j in range(0, kaisu):
    k = int(whohas[j])-1
    books[i][k] = 1


result = np.sum(books,axis=0)
a = np.count_nonzero(result)
print(sunuke - a)

Measured memory_bytes: 27344
dict = ["a","b","c","d","e","f","g","h","i","j","k","l","m",\
        "n","o","p","q","r","s","t","u","v","w","x","y","z"]
lsalpha = [1,3,5,7,9,11,15,17,19,21,23,25]

n = int(raw_input())
for roop in range(n):
    code = raw_input()
    for alpha in lsalpha:
        flag = 0
        for beta in range(26):
            decode = ""
            for chara in code:
                if chara != " ":
                    f = dict.index(chara)
                    for i in range(26):
                        if (alpha*i + beta)%26 == f:
                            dechara = dict[i]
                            break
                    decode += dechara
                else:
                    decode += " "
            if decode.count("that") > 0 or decode.count("this") > 0:
                flag = 1
                break
        if flag == 1:
            break
    print decode

Measured memory_bytes: 4260
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    
    
    int A,B;
    cin >> A >> B;
    if(B%A==0) cout << A+B << endl;
    else cout << B-A << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int a;
	string s;
	scan(a>>s);
	if(a>=3200) prin(s);
	else prin("red");
	return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int a,b,c,t,n,m,k;
    cin>>n;
    ll dp[n+1][3];
    cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
    
    for(int i=1;i<n;i++){
        cin>>a>>b>>c;
        dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b+max(dp[i-1][2],dp[i-1][0]);
        dp[i][2]=c+max(dp[i-1][0],dp[i-1][1]);
    }
    //for(int i=0;i<n;i++){
    //    for(int j=0;j<3;j++){
    //        cout<<dp[i][j]<<" ";
    //    }
    //    cout<<endl;
    //}
    cout<<(max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])));
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int dp[100010];
int s[100010];

int main()
{
  int N, M;
  cin >> N >> M;
  rep(i, N+1) s[i] = 0;
  rep(i, M) {
    int a;
    cin >> a;
    s[a] = 1;
  }
  
  dp[0] = 1;
  rep(i, N+1) {
    if (s[i]) { dp[i] = 0; continue; }
    if (i > 0) dp[i] = dp[i-1];
    if (i > 1) dp[i] += dp[i-2];
    dp[i] %= MOD;
  }
  cout << dp[N] << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define FORR(i, a, b) for(int i=(b-1);i>=(a);--i)
#define FORRE(i, a, b) for(int i=(b);i>=(a);--i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define repr(i, n) for(int i=(n-1);i>=0;--i)
#define repre(i, n) for(int i=(n);i>=0;--i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	
	if (n == 2) {
		cout << 0 << endl;
		return 0;
	}
//	if (n == 6) {
//		cout << 5 << endl;
//		return 0;
//	}
	
	ll sum = 0;
	for (ll i = 1; i * i < n; ++i) {
		if (n % i == 0) {
			ll num = n / i - 1;
			if (n / num == n % num) {
				sum += num;
			}
		}
	}
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000000000



int main(){
	
	int N;
	cin>>N;
	long long L;
	cin>>L;
	vector<long long> a(N);
	long long maxi = 0;
	int ind;
	for(int i=0;i<N;i++){
		cin>>a[i];
		if(i!=0){
			if(maxi<a[i]+a[i-1]){
				maxi = a[i]+a[i-1];
				ind = i;
			}
		}
	}
	if(maxi<L){
		cout<<"Impossible"<<endl;
		return 0;
	}
	
	cout<<"Possible"<<endl;
	for(int i=1;i<ind;i++){
		cout<<i<<endl;
	}
	for(int i=N-1;i>ind;i--){
		cout<<i<<endl;
	}
	cout<<ind<<endl;
	
	
	return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    string ans = "";
    rep (i, s.size()) {
        if (i%2 == 0) {
            ans += s[i];
        }
    }

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

Measured memory_bytes: 592
s = int,input()
i = list(map(int,input().split()))
err = 0
total = 0
while err == 0:
    count = 0
    for nom in i:
        if nom % 2 == 1:
            err = 1
            count += 1
        else:
            i[count] = nom / 2
            count += 1
    if err == 0:
        total += 1
print(total)

Measured memory_bytes: 38512
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll mod = static_cast<ll>(1e9) + 7;

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

    vector<ll> A(N);
    rep (i, N) { cin >> A[i]; }

    vector<ll> B(N + 1);
    fill(B.begin(), B.end(), 0);

    rep (i, N) { B[N] += (i % 2 ? -1 : 1) * A[i]; }

    for (ll i=N-1;i>=0;--i)
    {
        B[i] = (A[i] * 2) - B[i + 1];
    }

    rep (i, N) { cout << B[i] << " "; }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector< vector<ll> > node(0,vector<ll>(0));

vector<ll> color(0);

bool dfs(ll i,ll c){
  color[i]=c;
  for(auto n:node[i]){
    if( color[n] == c ) return false;
    if( color[n] == 0 && !dfs( n , -c ) ) return false;
  }
  return true;
}

int main(void){

  ll n,m;
  cin>>n>>m;
  rep(i,n){
    color.pb(0LL);
    node.pb(vector<ll>(0));
  }
  color.pb(0LL);
  node.pb(vector<ll>(0));

  rep(i,m){
    ll _a,_b;
    cin>>_a>>_b;
    node[_a].pb(_b);
    node[_b].pb(_a);
  }


  for(ll i=1;i<n+1;i++){
    if(color[i] == 0){
      if(dfs(i,1) == false){
        //cout << "not two!" << endl;
        cout << n*(n-1)/2 - m << endl;
        return 0;
      }
    }
  }
  //cout << "two!" << endl;
  ll b=0;
  ll w=0;
  for(ll i=1;i<n+1;i++){
    if(color[i]==1) b++;
    else if(color[i]==-1) w++;
  }
  //cout << b << "," << w << endl;
  cout << b*w-m << endl;

  return 0;
}


Measured memory_bytes: 7464