akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
   int x,n,ans,min=1000;  cin>>x>>n; int A[n];
   for(int i=0;i<n;i++){cin>>A[i];}
   sort(A,A+n);
  for(int i=-101;i<=101;i++)
  {
      if(binary_search(A,A+n,i)==0 && abs(x-i)<min){min=x-i; ans=i;}
  }
    
   cout<<ans; 
    
    
    
}

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

using ull = unsigned long long;
using ui = unsigned int;
int main() {
	ui n;
	std::cin >> n;

	std::vector<ull> an(n, ull{});

	for (auto&a : an)
		std::cin >> a;

	std::sort(std::begin(an), std::end(an));

	const auto min_2 = an[1];

	ull ans = 1;
	for (ull i{ min_2 }; i>=2; --i) {

		ui discount_{};
		for (ui j{ }; j < n; ++j) {
			discount_ += an[j] % i != 0 ? 1 : 0;
			if (discount_ >= 2)
				break;
		}

		if (discount_ <= 1) {
			ans = i;
			break;
		}
	}

	std::cout << ans <<"\n";

	return 0;
}

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

int main(){
  int m, f, r;
  char grade;
  while(true){
    cin >> m >> f >> r;
    if(m==-1 & f==-1& r==-1) break;
    if(m==-1 | f==-1) grade='F';
    else  if(m+f>=80) grade='A';
    else if(m+f<80&m+f>=65) grade='B';
    else if(m+f<65&m+f>=50) grade='C';
    else if(m+f<50&m+f>=30){
      if(r>=50) grade='C';
      else grade='D';
    }
    else grade='F';
    cout << grade << endl;
  }
}



Measured memory_bytes: 3076
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    int m = a[0];
    for(int i = 0; i<n; i++){
        m = gcd(a[i],m);
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt() - 1;
		}
		long[] d1 = new long[m + 1];
		long[] d2 = new long[m + 1];
		for (int i = 0; i + 1 < n; ++i) {
			int t = a[i + 1];
			int s = a[i];
			if (s <= t) {
				d1[0] += t - s;
				d1[s + 1] -= t - s;

				d1[s + 1] += t + 1;
				d1[t + 1] -= t + 1;
				d2[s + 1] += -1;
				d2[t + 1] -= -1;

				d1[t + 1] += t - s;
				d1[m] -= t - s;
			} else {
				
				d1[0] += t + 1;
				d1[t + 1] -= t + 1;
				d2[0] += -1;
				d2[t + 1] -= -1;

				d1[t + 1] += m + t - s;
				d1[s + 1] -= m + t - s;

				d1[s + 1] += t + m + 1;
				d1[m] -= t + m + 1;
				d2[s + 1] += -1;
				d2[m] -= -1;

			}
		}
		long ans = Long.MAX_VALUE;
		for (int i = 0; i < m; ++i) {
			if (i > 0) {
				d1[i] += d1[i - 1];
				d2[i] += d2[i - 1];
			}
		}
		for (int i = 0; i < m; ++i) {
			ans = Math.min(ans, d1[i] + d2[i] * i);
		}
		System.out.println(ans);
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			return (int) nextLong();
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 26196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<int,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n,j) for (int i = n; j<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

int main(){
  vector<vector<int>> vec(3,vector<int>(3));
  REP(i,0,3)REP(j,0,3)cin>>vec[i][j];
  bool flg=true;
  if((vec[0][0]-vec[1][0]!=vec[0][1]-vec[1][1])||(vec[0][1]-vec[1][1]!=vec[0][2]-vec[1][2]))flg=false;
  if((vec[1][0]-vec[2][0]!=vec[1][1]-vec[2][1])||(vec[1][1]-vec[2][1]!=vec[1][2]-vec[2][2]))flg=false;
  if((vec[2][0]-vec[0][0]!=vec[2][1]-vec[0][1])||(vec[2][1]-vec[0][1]!=vec[2][2]-vec[0][2]))flg=false;

  if((vec[0][0]-vec[0][1]!=vec[1][0]-vec[1][1])||(vec[1][0]-vec[1][1]!=vec[2][0]-vec[2][1]))flg=false;
  if((vec[0][1]-vec[0][2]!=vec[1][1]-vec[1][2])||(vec[1][1]-vec[1][2]!=vec[2][1]-vec[2][2]))flg=false;
  if((vec[0][2]-vec[0][0]!=vec[1][2]-vec[1][0])||(vec[1][2]-vec[1][0]!=vec[2][2]-vec[2][0]))flg=false;

  if(flg)print("Yes")
  else print("No")

}


Measured memory_bytes: 256
import itertools
N = int(input())
S = input()
out = S.count('R') * S.count('G') * S.count('B')

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))
for i in range(1, N):
  for j in range(N-i*2):
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      out -= 1
print(out)

Measured memory_bytes: 9208
import sys
input=sys.stdin.readline
l=[[0,0,0]]
r=[[0,0,0]]
n,c=map(int,input().split())
for i in range(n):
	x,v=map(int,input().split())
	r.append([x,v])
	l.append([c-x,v])
r.sort()
l.sort()
now=0
for i in range(n):
	now+=r[i+1][1]
	r[i+1].append(max(now-r[i+1][0],r[i][2]))
	if r[i+1][2]==r[i][2]:
		r[i+1][0]=r[i][0]
now=0
for i in range(n):
	now+=l[i+1][1]
	l[i+1].append(max(now-l[i+1][0],l[i][2]))
	if l[i+1][2]==l[i][2]:
		l[i+1][0]=l[i][0]
ans=0
for i in range(n+1):
	a=l[i][0]
	b=r[n-i][0]
	ans=max(l[i][2]+r[n-i][2]-min(a,b),ans)
print(ans)


Measured memory_bytes: 45648
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
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 ll mod = 1e9 + 7;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
const int IMAX = 200000;
ll fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
inline ll comb(int A, int B) {
	return fac[A] * ifac[B] % mod * ifac[A - B] % mod;
}

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


	int N;
	cin >> N;
	int C[200000];
	rep(i, N) cin >> C[i];
	sort(C, C + N);
	reverse(C, C + N);

	fac[0] = 1;
	rep1(i, IMAX) fac[i] = fac[i - 1] * i % mod;
	ifac[IMAX] = modpow(fac[IMAX], mod - 2);
	for (int i = IMAX; i > 0; i--) ifac[i - 1] = ifac[i] * i % mod;
	inv[0] = 1;
	rep1(i, IMAX) inv[i] = ifac[i] * fac[i - 1] % mod;

	ll kotae = 0;
	rep(i, N) {
		if (i == 0) kotae += C[i] * modpow(2, N - 1);
		else {
			kotae += (i + 2) * modpow(2, i - 1) % mod * C[i] % mod * modpow(2, N - i - 1) % mod;

		}
		kotae %= mod;
	}
	co(kotae * modpow(2, N) % mod);




	Would you please return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int max=0, maxnum=0;
    int max2=0;
    for(int x=0; x<num; x++){
      int in=scan.nextInt();
      if(max<=in && max2<=in && max!=in){
        max=in;
        maxnum=x;
      }else if(max>=in && max2<=in){
        max2=in;
      }
    }
    for(int x=0; x<num; x++){
      if(maxnum!=x){
        System.out.println(max);
      }else{
        System.out.println(max2);
      }
    }
  }
}

Measured memory_bytes: 82444
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int M = 10;
int main() {
  long N;
  cin >> N;

  vector<long> candi[11];
  candi[0].push_back(0);

  for (int i = 1; i <= M; i++) {
    for (int j = 0; j < candi[i - 1].size(); j++) {
      long current = candi[i - 1][j];
      candi[i].push_back(current * 10 + 3);
      candi[i].push_back(current * 10 + 5);
      candi[i].push_back(current * 10 + 7);
    }
  }

  vector<long> candiAll;
  for (int i = 1; i <= M; i++) {
    candiAll.insert(candiAll.end(), candi[i].begin(), candi[i].end());
  }

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

  vector<long> newCandiAll;
  for (int i = 0; i < candiAll.size(); i++) {
    string str = to_string(candiAll[i]);
    if ((str.find("3") != string::npos) && (str.find("5") != string::npos) &&
        (str.find("7") != string::npos)) {
      newCandiAll.push_back(candiAll[i]);
    }
  }

  int i = 0;
  for (i = 0; i < newCandiAll.size(); i++) {
    if (newCandiAll[i] > N) break;
  }

  cout << i << endl;

  return 0;
}

Measured memory_bytes: 2904
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		int[][] alp = new int[26][s.length+1];
		int front = 0; long count = 0;
		int[] half = new int[26];

		for(int i = 0; i < 26; i++) {
			for(int j = 0; j < s.length+1; j++) {
				alp[i][j] = 0;
			}
		}

		for(int i = 0; i < s.length; i++) {
			int a = s[i] - 97;
			alp[a][0]++;
			alp[a][alp[a][0]] = i;
 		}

		for(int i = 0; i < t.length; i++) {
			int x = t[i] - 97;
			if(alp[x][0] == 0) {
				System.out.println(-1);
				System.exit(0);
			}
		}

		for(int i = 0; i < 26; i++) {
			half[i] = alp[i][alp[i][0]/2+1];
		}

		for(int j = 0; j < t.length; j++) {
			int x = t[j] - 97;
			int last = alp[x][0];

			if(front > alp[x][last]) {
				count++;
				front = alp[x][1]+1;
			}else {
				int a = (front > half[x]) ? alp[x][0]/2+1 : 1;
				while(true) {
					if(alp[x][a] >= front) {
						front = alp[x][a]+1;
						break;
					}
					a++;
				}
			}
		}
		long len = s.length;
		long ans = count*len + front;

		System.out.println(ans);
		sc.close();
	}

}

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

#define int long long
#define pb push_back
#define fi first
#define se second

const int N=1e5+5;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;

int n,ans;
int pset[N],s[N];
vector<ii> vx,vy;
map<ii,int> ma;
priority_queue<iii,vector<iii>,greater<iii> > pq;

bool how_sort(ii a,ii b){
    if(a.se!=b.se)
            return a.se<b.se;
    return a.fi<b.fi;
}

int unionfind(int u){
    return (u==pset[u]) ? u : (pset[u]=unionfind(pset[u]));
}
bool compare(int u,int v){
    return (unionfind(u)==unionfind(v)) ? true :false;
}
void unionset(int i,int j)
{
    int x=unionfind(i),y=unionfind(j);
    if(s[x]>s[y]){
        pset[y]=x;
        s[x]+=s[y];
    }
    else{
        pset[x]=y;
        s[y]+=s[x];
    }
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int cnt=0;
    cin>>n;
    for(int i=1;i<=n;++i){
        int a,b;
        cin>>a>>b;
        if(ma[ii(a,b)])continue;
        ma[ii(a,b)]=++cnt;
        vx.pb(ii(a,b));
        vy.pb(ii(a,b));
        pset[cnt]=cnt;
        s[cnt]=1;
    }
    sort(vx.begin(),vx.end());
    sort(vy.begin(),vy.end(),how_sort);
    
	// dat09
    for(int i=1;i<vx.size();++i){
        int a=vx[i].fi-vx[i-1].fi;
        pq.push(iii(a,ii(ma[vx[i]],ma[vx[i-1]])));
	
        int b=vy[i].se-vy[i-1].se;
        pq.push(iii(b,ii(ma[vy[i]],ma[vy[i-1]])));
    }
    while(!pq.empty()){
        iii x=pq.top();
        int w=x.fi,u=x.se.fi,v=x.se.se;
        pq.pop();
        if(!compare(u,v)){
            unionset(u,v);
            ans+=w;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 20700
import java.io.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a, b;

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

		a = Integer.parseInt(strArr[0]);
		b = Integer.parseInt(strArr[1]);

		if(a < b){
			System.out.println("a < b");
		}
		else if(a > b){
			System.out.println("a > b");
		}
		else{
			System.out.println("a == b");
		}

	}
}

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

#define MAX 100001
typedef long long ll;

ll dp[MAX];
ll height[MAX];

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

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

    dp[0] = 0;
    dp[1] = abs(height[1]-height[0]);
    for(int i = 2; i < n; i++){
        ll mincost = INT_MAX;
        for(int j = 1; j <= k; j++){
            if(i-j >= 0){
                mincost = min(abs(height[i]-height[i-j])+dp[i-j],mincost);
            }
        }
        dp[i] = mincost;
    }

    cout << dp[n-1] << "\n";
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer serch = nil->next;
  while(serch != nil && serch->key != key){
    serch = serch->next;
  }
  return serch;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil)return;//tがheadだったら消さない
  t->prev->next = t->next;//前から後ろに繋げてあげる
  t->next->prev = t->prev;//後ろから前に繋げてあげる
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;//(11)
  nil->next->prev = x;//(12)
  nil->next = x;//(13)
  x->prev = nil;//(14)

  /*
□(prev->(2))□(nil)□(next->(1))
□(prev->(2))□(key')□(next->(1))

□□(nil)□
↑(14)   ↓(13)
□□(key)□
↑(12)   ↓(11)
□□(key')□
  */

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        delete(key); nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 33020
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>

using namespace std;

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

//10^9 + 7
const ll MOD = 1000000007;

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

	string ans = "No";
	if (a + 2 * sqrtl(a * b) + b < c) {
		ans = "Yes";
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[55],b[55];
int l;
int main(){
    cin>>a>>b;
    l=strlen(b);
    for(int i=0;i<l;i++) cout<<a[i]<<b[i];
    if(strlen(a)>strlen(b)) cout<<a[l];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s1;
  string s2;
  int n;
  cin >> n;
  cin >> s1;
  cin >> s2;

  for(int i=0;i<n;i++)
  {
    cout << s1[i];
    cout << s2[i];
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(int (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(int (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

int main()
{
    ll n,a,ans1 = 0,ans2 = 0,cnt;
    cin >> n;
    rep0(i, n){
        cin >> a;
        if (ans1 <= a) {
            ans2 = ans1;
            ans1 = a;
            cnt = i;
        }else if (ans2 < a){
            ans2 = a;
        }
    }
    rep0(i, n){
        if (i != cnt)cout << ans1 << endl;
        else cout << ans2 << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
int main(){
    string S;
    cin >> S;
    int a = 0;
    int b = 0;
    int c = 0;
    for(int i=0; i<3; i++){
        if(S[i] == 'a') a++;
        if(S[i] == 'b') b++;
        if(S[i] == 'c') c++;
    }
    if(a==1 && b==1 && c==1) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    string s;
    cin >> s;
    bool fl = false;
    rep(i,3) if(s[i]=='7') fl = true;
    if(fl) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

#define ll                     long long int
#define endl                   '\n'

static const int maxn = 2e5 + 5;

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);
      cout << fixed << setprecision(8);

      //freopen("in.txt", "r", stdin);

      int n;
      cin >> n;
      priority_queue <double, vector <double>, greater <double> > pq;
      for (int i = 0; i < n; i++)
      {
            double x;
            cin >> x;
            pq.push(x);
      }
      while (pq.size() > 1)
      {
            double x = pq.top(); pq.pop();
            double y = pq.top(); pq.pop();
            //cerr << x << ' ' << y << endl;
            double mix = (x + y) / 2.0;
            pq.push(mix);
      }
      cout << pq.top() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n;
    scanf("%d",&n);
    int A[n];
 
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
 
    for(int i = n-1; i > 0; i--) printf("%d ",A[i]);
    printf("%d\n",A[0]);
}


Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(int (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(int (i)=(a)-1;(i)>=(b);(i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define VI vector<int>
#define VII vector<VI>
#define VL vector<LL>
#define VLL vector<VL>
#define VD vector<double>
#define VDD vector<VD>
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<LL,LL>
#define VPII vector<PII>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EP emplace_back
#define FORE(a,b) for(auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9;
const int MOD=INF+7;

int main(void){
    int N; cin>>N;
    VI A(N);
    REP(i,N) cin>>A[i];
    int ans=INF;
    FOR(j,-100,101){
        int res=0;
        REP(i,N){
            res+=pow((A[i]-j),2);
        }
        ans=min(ans,res);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def f(n):
    if(n%2 == 0):return(n//2)
    else:return(3*n+1)

s = int(input())

a = [s]
for i in range(100000):
    x = f(a[i])
    if(x in a):
        print(i + 2)
        exit()
    a.append(x)


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


int test1(string s) {
  int r=0;
  
  if (s.substr(0,7)=="dreamer") r=7;
  else if (s.substr(0,5)=="dream") r=5;
  else if (s.substr(0,6)=="eraser") r=6;
  else if (s.substr(0,5)=="erase") r=5;
  
  return r;
}

int main() {
  string str;
  cin >> str;

  int r;
  while(str.size()>0) {
    r=test1(str);
    if(r==0) {
      r=-1;
      break;
    }
    
    if(r==7) {
      if (str.size()>7 && test1(str.substr(r))==0) r=5;}
    str=str.substr(r);
  }
  
  if(r==-1) cout << "NO" <<endl;
  else cout << "YES" <<endl;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int [] array = new int[200000];
		Arrays.fill(array,1);
		for(int i=0;i<n;i++) {
			array[i] = sc.nextInt();
		}
		sc.close();

//		long MOD = 1000000007L;
//		long[] bigArray = new long[n-k+1];
//		bigArray[0] = 1L;
//
//		for(int i=0;i<k;i++) {
//			bigArray[0] = bigArray[0]*array[i];
//		}

		for(int i=0;i<n-k;i++) {
//			bigArray[i+1] = bigArray[i]/array[i]*(array[i+k]);
			if(array[i]<array[i+k]) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 60028
N = gets.to_i
a = gets.split.map(&:to_i)
flg = 0; cnt = 0
loop do
  N.times do |i|
    flg = 1 if a[i] % 2 == 1
    a[i] = a[i] / 2
  end
  if flg == 1 then
    break
  end
  cnt += 1
end

print("#{cnt}\n")

Measured memory_bytes: 1788
n = int(input())
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

if __name__ == '__main__':
    print(n,end=":")
    print("",*prime_factors(n))



Measured memory_bytes: 5596
INF = 10 ** 19
s = list(input())
t = list(input())
N = len(s)
M = len(t)

def check(s,t):
    res = 0
    for i in range(M):
        if s[i] != t[i]:
            res += 1
    return res

ans = INF
for i in range(N-M+1):
    ans = min(ans, check(s[i:i+M], t))
print(ans)

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define TMP 1000000007

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
	int x;
	scanf("%d", &x);
	printf("%s\n", (x >= 1200) ? "ARC" : "ABC");
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double dp[5002][5020];
int main()
{
    int a,b,c,i,j;
    cin>>a;
    double ss=0,s[a];
    for(i=0; i<a; i++)
    {
        cin>>s[i];
    }
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(i=0; i<a; i++)
    {
        for(j=0; j<i+1; j++)
        {
            dp[i+1][j+1]+=dp[i][j]*s[i];
            dp[i+1][j]+=dp[i][j]*(1.0-s[i]);
        }
    }
    for(i=a; i>=(a+1)/2; i--)
    {
        ss+=dp[a][i];
    }
    cout<<fixed<<setprecision(10)<<ss<<endl;
    return 0;
}


Measured memory_bytes: 196480
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

struct Edge {
    ll to;
    ll cost;
    Edge (ll _t, ll _c) {
        to = _t;
        cost = _c;
    }
};

ll N,M;
vector<Edge> G[100010];
ll dist[100010];
const ll INF = 1e18;

int main ()
{
    cin >> N >> M;
    for (int i = 1; i < N; i++) {
        G[i + 1].push_back(Edge(i, 0));
    }
    REP(i,M) {
        ll L,R,C;
        cin >> L >> R >> C;
        G[L].push_back(Edge(R, C));
    }

    fill(dist, dist + 100010, INF);
    reversed_priority_queue<tuple<ll,ll>> que;
    que.push(make_tuple(0, 1));

    while(!que.empty()) {
        ll dt,idx;
        tie(dt,idx) = que.top();
        que.pop();
        if (dist[idx] < dt) {
            continue;
        }
        REP(i,G[idx].size()) {
            ll ndt = dt + G[idx][i].cost;
            if (dist[G[idx][i].to] > ndt) {
                dist[G[idx][i].to] = ndt;
                que.push(make_tuple(ndt, G[idx][i].to));
            }
        }
    }

    if (dist[N] == INF) {
        cout << -1 << endl;
        return 0;
    }

    cout << dist[N] << endl;

    return 0;
}


Measured memory_bytes: 10232
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,j,c,cnt=0;
    cin>>n;
    for(i=1;i<=n;i++){
        c=0;
        if(i%2!=0){
            for(j=1;j*j<=i;j++){
                if(i%j==0){
                    if(j==(i/j)) c+=1;
                    else c+=2;
                }
            }
        }
        if(c==8){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


const int INF = 1<<30;
int N, Q;
string S;
vector<set<int> > pls;

void solve() {
    pls.assign(26, set<int>({INF}));
    N = S.size();
    for (int i = 0; i < N; ++i) pls[S[i] - 'a'].insert(i);

    while (Q--) {
        int type; cin >> type;
        if (type == 1) {
            int ind; char nc; cin >> ind >> nc; --ind;
            auto pc = S[ind];
            S[ind] = nc;
            pls[pc - 'a'].erase(ind);
            pls[nc - 'a'].insert(ind);
        }
        else {
            int l, r; cin >> l >> r; --l;
            int res = 0;
            for (int c = 0; c < 26; ++c) {
                if (pls[c].empty()) continue;
                int lid = *pls[c].lower_bound(l);
                int rid = *pls[c].lower_bound(r);
                if (rid > lid) ++res;
            }
            cout << res << endl;
        }
    }
}

int main() {
    while (cin >> N >> S >> Q) {
        solve();
    }
}


















Measured memory_bytes: 24196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int a[500],b[500],cnt[500],x[500];
ll fpm(ll a,ll b){
	ll res=1ll;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)res=res*a%mod;
	return res;
}
int n,c;
ll ans;
ll tmp[4000],ret[4000];
//ll f(){
//	static ll ret[4000],tmp[4000];
//	memset(ret,0,sizeof ret);
//	memset(tmp,0,sizeof tmp);
//	for(int i=0;i<=c;++i){
//		tmp[i]=fpm(x[1],i);
//	}
//	if(n==1)return tmp[c];
//	for(int k=2;k<=n;++k){
//		memset(ret,0,sizeof ret);
//		for(int i=0;i<=c;++i){
//			for(int j=0;j<=c;++j){
//				ret[i+j]=(ret[i+j]+fpm(x[k],i)*tmp[j]%mod)%mod;
//			}
//		}
//		memcpy(tmp,ret,sizeof tmp);
//	}
//	return ret[c];
//}
ll F[4000][4000];
int main(){
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i);
	for(int i=1;i<=n;++i)
		scanf("%d",b+i);
	for(int pos=1;pos<=n;++pos){
		for(int j=0;j<=c;++j){
			for(int i=a[pos];i<=b[pos];++i){
				F[pos][j]=(F[pos][j]+fpm(i,j))%mod;
			}
		}
	}
	for(int i=0;i<=c;++i){
		tmp[i]=F[1][i];
	}
	if(n==1)ans=tmp[c];
	else{
		for(int k=2;k<=n;++k){
			memset(ret,0,sizeof ret);
			for(int i=0;i<=c;++i){
				for(int j=0;j<=c;++j){
					ret[i+j]=(ret[i+j]+F[k][i]*tmp[j]%mod)%mod;
				}
			}
			memcpy(tmp,ret,sizeof tmp);
		}
		ans=ret[c];
	}
	printf("%lld\n",ans);
	return 0;
}
/*
2 3
1 1
1 1

3 1
1 1 1
1 1 1

2 1
1 1
2 1

2 1
1 1
1 1

2 
*/

Measured memory_bytes: 13056
#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool matches(int N, int M, const vector<string> &A, const vector<string> &B, int i, int j)
{
	for (int s = 0; s < M; ++s) {
		for (int t = 0; t < M; ++t) {
			if (A[i + s][j + t] != B[s][t]) {
				return false;
			}
		}
	}
	return true;
}

bool matches(int N, int M, const vector<string> &A, const vector<string> &B)
{
	for (int i = 0; i <= N - M; ++i) {
		for (int j = 0; j <= N - M; ++j) {
			if (matches(N, M, A, B, i, j)) {
				return true;
			}
		}
	}
	return false;
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<string> A(N), B(M);
	
	for (auto &A_i : A) cin >> A_i;
	for (auto &B_i : B) cin >> B_i;

	if (matches(N, M, A, B)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

ll powa(ll a)
{
    return (a*a*a*a*a);
}

int main()
{
   FAST/**/
   
   ll x;
   cin>>x;
   
   for(ll a=-1000;a<=1000;a++)
   {
       for(ll b=-1000;b<=1000;b++)
       {
           ll temp = powa(a) - powa(b);
           if(temp == x)
           {
               cout<<a<<" "<<b<<"\n";
               return 0;
           }
       }
   }
   
   
   return 0;        
}  
  
   

Measured memory_bytes: 3648
#include<cstdio>
int main()
{
    int a,b,c,x;
    int countn,sum;
    while(~scanf("%d%d%d%d",&a,&b,&c,&x))
    {
        countn=0;
        for(int i=0;i<=a;i++)
            for(int j=0;j<=b;j++)
               for(int k=0;k<=c;k++)
        {
             sum=i*500+j*100+k*50;
             if(sum==x)
                countn++;
        }
        printf("%d\n",countn);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1LL << 60;
const ll C = 1000000000+7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    int min_value = 100000, min_index;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        if(min_value > A[i]) {
            min_index = i;
            min_value = A[i];
        }
    }
    
    int count = 1;
    N -= K;
    while(N > 0) {
        N -= (K-1);
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k,t,ans,s=0;cin>>k>>t;
  lvector A(t);rep(i,t) {cin>>A[i];s+=A[i];}
  sort(RALL(A));s-=A[0];
  if(t==1) ans=A[0]-1;
  else ans=max(0ll,A[0]-s-1);
  print(ans);
  return 0;
}


Measured memory_bytes: 256
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}



fn main() {
    input!{
        n: i64,
        k: usize,
        d_v: [i64; k],
    }

    let d_v: Vec<char> = d_v.iter()
        .map(|&i| std::char::from_digit(i as u32, 10).unwrap())
        .collect();

    'a: for answer in n.. {
        let answer_s = answer.to_string();
        let answer_v: Vec<char> = answer_s.chars().collect();
        for c in &d_v {
            if answer_v.contains(c) {
                continue 'a;
            }
        }

        println!("{}", answer);
        return;
    }
}



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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    int res = 0;
    int sum = 0;
    int el;
    for(int i = 0; i < n; ++i){
        cin >> el;
        res -= el*el;
        sum += el;
    }
    res += sum*sum;
    res /= 2;
    cout << res << endl;
}

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

int main() {
	ll n; cin >> n;
	vector<ll>ans;
	while (n > 0) {
		ans.push_back(n % 26);
		n -= n % 26;
		n /= 26;
	}
	for (int i = 0; i < ans.size() - 1; i++) {
		if (ans.at(i) <= 0) {
			ans.at(i) += 26;
			ans.at(i + 1) -= 1;
		}
	}
	reverse(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++) {
		if (ans.at(i) == 0)continue;
		char x = 'a' - 1 + ans.at(i);
		cout << x;
	}
	cout << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  if ((a == 'H' && b == 'H') || a == 'D' && b == 'D') cout << "H" << endl;
  else cout << "D" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.util.*
import kotlin.math.max

fun main() = abc175e()

@OptIn(ExperimentalStdlibApi::class)
fun abc175e() = SimpleFastIOWithToken_abc175e().exec {
    val (rows, cols, k) = List(3) { readInt() }

    val grid = Array(rows) { LongArray(cols) }
    repeat(k) { grid[readInt() - 1][readInt() - 1] = readLong() }

    val rowMaxes = LongArray(cols)

    for (y in 0 until rows) {
        val rowDp = Array(4) { LongArray(cols) }
        rowDp[0] = rowMaxes

        for (x in 0 until cols) {
            val point = grid[y][x]
            if (point > 0) for (take in 2 downTo 0) {
                rowDp[take + 1][x] = max(rowDp[take + 1][x], rowDp[take][x] + point)
            }

            if (x + 1 < cols) for (take in 0..3) {
                rowDp[take][x + 1] = max(rowDp[take][x + 1], rowDp[take][x])
            }
            for (take in 0..3) rowMaxes.changeMax(x, rowDp[take][x])
        }
    }

    val answer = rowMaxes.last()

    println(answer)
}

private fun LongArray.changeMax(i: Int, v: Long) = run { this[i] = max(this[i], v) }

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc175e(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc175e.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 147252
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    string S, T; cin >> S >> T;
    int N = S.size();
    int s[26], t[26];
    rep(i, 26) {
        s[i] = -1;
        t[i] = -1;
    }
    rep(i, N) {
        int a = S[i] - 'a', b = T[i] - 'a';
        if(s[a] >= 0) if(s[a] != b) No();
        if(t[b] >= 0) if(t[b] != a) No();
        if(s[a] == -1) s[a] = b;
        if(t[b] == -1) t[b] = a;
    }
    Yes();
	return 0;
}

Measured memory_bytes: 916
N = int(input())
D1, D2 = [], []
for i in range(N):
  li = list(map(int,input().split()))
  D1.append(li[0])
  D2.append(li[1])

D = ""

for i in range(N):
  if D1[i]==D2[i]:
    D += 'T'
  else:
    D += 'F'

if 'TTT' in D:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
int bikkuri(int n){
    int ans = 1 ;
    for (size_t i = 1; i < n+1; i++)
    {
        ans *= i ;
    }
    return ans ;
}
int main(){
    int n ;
    cin >> n ;
    vector<int> p(n),q(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> p.at(i) ;
    }
    for (size_t i = 0; i < n; i++)
    {
        cin >> q.at(i) ;
    }
    int ordp = 0;
    int ordq = 0;

    for (size_t i = 0; i < n-1; i++)
    {
        ordp += p.at(i) * bikkuri(n-1-i) ;
        ordq += q.at(i) * bikkuri(n-1-i) ;
        for (size_t j = i+1; j < n; j++)
        {
            if (p.at(j) > p.at(i))
            {
                p.at(j) -- ;
            }
            
        }
        for (size_t j = i+1; j < n; j++)
        {
            if (q.at(j) > q.at(i))
            {
                q.at(j) -- ;
            }
            
        }
        
    }
    
    cout << abs(ordp-ordq) << endl ;
}    

Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package here;

/**
 *
 * @author sokumar
 */
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter w = new PrintWriter(System.out);
        String s = sc.next();
        String t = sc.next();
        int [][]dp = new int[s.length()+1][t.length()+1];
        for(int i=1;i<=s.length();i++)
        {
            for(int j=1;j<=t.length();j++)
            {
                if(s.charAt(i-1)==t.charAt(j-1))
                    dp[i][j] = dp[i-1][j-1]+1;
                else
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                
            }
        }
        int i = s.length();
        int j = t.length();
        StringBuilder sb = new StringBuilder();
        while(i > 0 && j > 0)
        {
            if(s.charAt(i-1)==t.charAt(j-1))
            {
                sb.append(Character.toString(s.charAt(i-1)));
                i--;
                j--;
                
            }
            else
            {
                if(dp[i][j-1]>= dp[i-1][j])
                {
                    j--;
                }
                else
                {
                    i--;
                }
            }
        }
        w.println(sb.reverse());
        w.close();
    }
    
}


Measured memory_bytes: 83148
n = int(input())
l = list(map(int, input().split()))
l.sort()

# a, bをfixしてcを探索
# n*n*logn
# c_i < a+b をにぶたん
def binary_search(list, item):
    # listからitem未満の最大のindexを取得
    low = 0
    high = len(list) - 1
    if list[high] < item:
        return high+1
    if list[low] >= item:
        return low
    while True:
        mid = (low + high) //2
        guess = list[mid]
        if high - low <= 1:
            return high
        if guess >= item:
            high = mid
        else:
            low = mid

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        a = l[i]
        b = l[j]
        c = binary_search(l, b+a)
        ans += c-(j+1)
print(ans)


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

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  int n = max(a,b);
  vector<int>p;
  for (int i = 1; i <= (n); ++i){
    if(a%i==0 && b%i==0) p.push_back(i);
  }
  cout << p[p.size()-k] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n, m, sum = 0;
  cin>>n>>m;
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin>>v[i];
    sum += v[i];
    v[i] *= (4 * m);
  }
  sort(v.begin(), v.end());
  int cnt = 0;
  for(int i=0; i<n; i++) cnt += (v[i] >= sum);
  cout<<(cnt < m ? "No" : "Yes")<<endl;
}

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

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int W, H, ans;
string maze[20];

bool check(int x, int y){
	return x >= 0 && x < W && y >= 0 && y < H && maze[y][x] == '.';
}

void dfs(int x, int y){
	
	for(int i = 0; i < 4; ++i){
		int nx = x + dx[i], ny = y + dy[i];
		if(check(nx, ny)){
			maze[ny][nx] = '#';
			ans++;
			dfs(nx, ny);
		}
	}
}

int main() {
	while(cin >> W >> H && (W || H)){
		for(int i = 0; i < H; ++i)
				cin >> maze[i];
		
		ans = 0;
		for(int i = 0; i < H; ++i){
			for(int j = 0; j < W; ++j){
				if(maze[i][j] == '@'){
					dfs(j, i);
				}
			}
		}
		cout << ans + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1220