akhauriyash/Code-Regression huggingface dataset:
#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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= n; j += i) {
            ans += j;
        }
    }
    cout << ans << "\n";
}

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

using namespace std;

int n, m;

vector<string> gen;
void solve(string s) {
  if (s.length() > n || s.length() > 1 && s.front() == '0')
    return;
  if (s.length() == n) {
    gen.push_back(s);
  }
  for (char i = '0'; i <= '9'; i++)
    solve(s + i);

}
int main() {
  cin >> n >> m;
  solve("");
  vector<pair<int, int>> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i].first >> a[i].second;
  }
  for (auto x : gen) {
    bool ok = true;
    //cout << x << '\n';
    for (auto y : a) {
      if (x[y.first - 1] != (char) (y.second + '0')) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << x << '\n';
      return 0;
    }
  }
  cout << -1;
  return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 
  fast;
 string v;
 cin>>v;
 ll d;
 cin>>d;
 ll n=v.size();

 vector<vector<ll> > dp(d,vector<ll>(2,0));
 for(ll i=0;i<v[0]-48;i++)
 	dp[i%d][0]++;

 dp[(v[0]-48)%d][1]++;

 for(ll i=1;i<n;i++)
 {
 		vector<vector<ll> > temp(d,vector<ll>(2,0));

 		for(ll j=0;j<d;j++)
 		{
 			for(ll dig=0;dig<10;dig++)
 				(temp[(dig+j)%d][0]+=dp[j][0])%=mod;


 			for(ll dig=0;dig<=v[i]-48;dig++)
 			{
 				bool f=1;
 				if(dig<v[i]-48)
 					f=0;
 				(temp[(dig+j)%d][f]+=dp[j][1])%=mod;
 			}
 		}
 		dp=temp;
 }

cout<<(dp[0][0]+dp[0][1]-1+mod)%mod;

}



Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[5]:


A,V = map(int, input().split())
B,W = map(int, input().split())
T = int(input())


# In[6]:


if V <= W:
    print("NO")
else:
    if abs(A-B) > T*(V-W):
        print("NO")
    else:
        print("YES")


# In[ ]:






Measured memory_bytes: 9172
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int mod = 1e9+7;
int32_t main(){  
    int n,k;
    cin >> n >> k;
    int ans = 0;
    for(int i = k ; i <= n+1 ;i++){
      //cout << n*i << " " << i*(i-1)  << " " << i << "\n";
      ans= (ans + (((n*i)%mod -(i*(i-1))%mod)%mod +1)%mod)%mod;
      //cout << ans << "****\n";
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	int n,i,r,last,time,day;
	for(;cin>>n,n;){
		vector<pair<int,string> >program;
		set<string>precious;
		{
			string s;
			map<string,int>m;
			for(;n--;){
				cin>>s>>day>>time;
				program.push_back(make_pair(day*1440+time/100*60+time%100,s));
				m[s]=day*1440+time/100*60+time%100;
			}
			bool flg=true;
			for(cin>>n;n--;){
				cin>>s;
				set<string>::iterator it=precious.begin();
				for(;it!=precious.end();it++){
					if(abs(m[*it]-m[s])<30)flg=false;
				}
				precious.insert(s);
			}
			if(!flg){puts("-1");continue;}
		}
		sort(program.begin(),program.end());
		for(last=r=i=0;i<program.size();i++){
			if(program[i].first>=last){
				last=program[i].first+30;
				r++;
			}else if(precious.find(program[i].second)!=precious.end()){
				last=program[i].first+30;
			}
		}
		printf("%d\n",r);
		next:;
	}
}

Measured memory_bytes: 1316
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;
vector<ll> dp;
ll go(ll sum,ll curr){
    if(curr > sum)
        return 0;
    if(curr == sum)
        return 1;
    if(dp[curr] != -1)
        return dp[curr];
    ll ans = 0;
    for(ll i=3;i<=sum;i++)
        ans = (ans%mod + go(sum,curr+i)%mod)%mod;
    return dp[curr] = ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll k;
    cin>>k;
    dp = vector<ll> (k+1,-1);
    if(k<3){
        cout<<"0"<<endl;
        return 0;
    }
    cout << go(k,0) << endl;
    return 0;
}



Measured memory_bytes: 3576
#include<algorithm>//STL通用算法
 
#include<bitset>//STL位集容器
 
//#include<bits/stdc++.h>//编译器GCC 4.8支持的万能头文件，基本包含所有头文件
 
#include<cctype>//C字符处理
 
#include<cerrno>//C的错误报告机制
 
#include<clocale>
 
#include<cmath>//兼容C语言数学库
 
#include<complex>//复数类
 
#include<cstdio>//C语言输入输出工具
 
#include<cstdlib>//C语言通用工具
 
#include<cstring>//C字符串
 
#include<ctime>
 
#include<deque>//STL双端队列容器
 
#include<exception>//异常处理类
 
#include<fstream>//文件输入输出流
 
#include<functional>//STL定义运算函数（代替运算符）
 
#include<limits>
 
#include<list>//STL线性列表容器
 
#include<map>//STL映射容器
 
#include<iomanip>
 
#include<ios>//基本输入/输出支持
 
#include<iosfwd>//输入/输出系统使用的前置声明
 
#include<iostream>//基本输入输出流
 
#include<queue>//STL队列容器
 
#include<set>//STL集合容器
 
#include<sstream>//基于字符串的流
 
#include<stack>//STL堆栈容器
 
#include<stdexcept>//标准异常类
 
#include<streambuf>//底层输入/输出支持
 
#include<string>//字符串类
 
#include<utility>//STL通用模板类
 
#include<vector>//STL动态数组容器
 
#include<cwchar>
 
#include<cwctype>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s=="ABC")
	    puts("ARC");
	else
	    puts("ABC");
}


Measured memory_bytes: 3624
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();
	static Node[] V;
	static ArrayDeque<Integer> que = new ArrayDeque<>();

	public static void main(String[] args) {
		int n = sc.nextInt();	
		int m = sc.nextInt();
		
		V = new Node[n];
		for(int i=0; i<n; i++) {
			V[i] = new Node();
		}
		
		for(int i=0; i<m; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			
			V[s].adj.add(t);
			V[t].adj.add(s);
		}
	
		int label = 0;
		for(int i=0; i<n; i++) {
			if(V[i].label == -1) {
				que.add(i);
				while(!que.isEmpty()) {
					V[que.poll()].setLabel(label);
				}
				label++;
			}
		}
		
		int q = sc.nextInt();
		for(int i=1; i<=q; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			if(V[s].label == V[t].label) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}

	static class Node {	
		int label = -1;
		ArrayList<Integer> adj = new ArrayList<>();
		
		public void setLabel(int label) {	
			this.label = label;
			for(int i=0; i<adj.size(); i++) {
				if(V[adj.get(i)].label == -1) {
					que.add(adj.get(i));
				}
			}
		}
	}

	static class FastScanner {
	    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 static 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() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

Measured memory_bytes: 79496
#include <stdio.h>

int main(){

  int x, y, z;

  scanf("%d%d", &x, &y);

  while(1){

    z = x % y;

    if(z == 0) break;

    x = y;

    y = z;

  }

  printf("%d\n", y);

  return 0;
}

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

int main() {
	int n,m;
	cin >> n >> m;
	vector<char> k(n,' ');
	for(int i = 0;i < m;i++)
	{
		int s;
		char c;
		cin >> s >> c;
		if(k.at(s - 1) != ' ' && 
		   k.at(s - 1) != c)
		{
			cout << "-1" << endl;
			return 0;
		}
		if(n > 1 && s == 1 && c == '0')
		{
			cout << "-1" << endl;
			return 0;
		}
		k.at(s - 1) = c;
	}
	if(k.at(0) == ' ')
	{
		if(n == 1)
		{
			k.at(0) = '0';
		}
		else
		{
			k.at(0) = '1';
		}
	}
	if(n > 1)
	{
		for(int i = 1;i < n;i++)
		{
			if(k.at(i) == ' ')
			{
				k.at(i) = '0';
			}
		}
	}
	for(int i = 0;i < n;i++)
	{
		cout << k.at(i);
	}
	cout <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    int a, b, k, c = 0;
    cin >> a >> b >> k;
    for (int i = 100; i > 0; i--){
        if(a % i == 0 && b % i == 0){
            c++;
        }
        if (k == c){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,z;
    cin>>a>>b;
    z=a+b;
    if(z%2==0){
        cout<<z/2<<endl;
      }
 else if(z%2>0){
   cout<<z/2+1<<endl;  
  }
        else{
            cout<<z/2<<endl;
        }
    
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

vector<int> graph[100005];
vector<int> sorted;
vector<bool> used(100005);
vector<int> dist(100005);

void dfs(int pos) {
  if (used[pos]) return;
  used[pos] = true;
  for(auto e: graph[pos]) {
    dfs(e);
  }
  sorted.push_back(pos);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  rep(i, m) {
    int x, y; cin >> x >> y;
    graph[x].push_back(y);
  }

  // topological sort
  for(int i=1; i<=n; i++) {
    dfs(i);
  }
  reverse(sorted.begin(), sorted.end());
  
  for(auto pos: sorted) {
    int now = dist[pos];
    for(auto e: graph[pos]) {
      dist[e] = max(dist[e], now+1);
    }
  }
  
  int ans = 0;
  for(int i=1; i<=n; i++) {
    ans = max(ans, dist[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 8828
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    vector<ll> v(3);

   for (int i = 0; i < 3; i++)
   {
       cin >> v[i];
   }

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

   ll ans = 0;

   ans = v[2] * 10 + v[1] + v[0];

   cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  int N;
  cin>>N;
  FOR(i,0,N){
    char C;
    cin>>C;
    if(C=='Y'){
      cout<<"Four"<<endl;
      return 0;
    }
  }
  cout<<"Three"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    char S = sc.next().charAt(0);
    if(S=='A' ){
      System.out.println("A");
      return;
    }
    if(S=='B' ){
      System.out.println("A");
      return;

    }
    if(S=='C' ){
      System.out.println("A");
      return;
    }
    if(S=='D' ){
      System.out.println("A");
      return;
    }
    if(S=='E' ){
      System.out.println("A");
      return;
    }
    if(S=='F' ){
      System.out.println("A");
      return;
    }
    if(S=='G' ){
      System.out.println("A");
      return;
    }
    if(S=='H' ){
      System.out.println("A");
      return;
    }
    if(S=='I' ){
      System.out.println("A");
      return;
    }
    if(S=='J' ){
      System.out.println("A");
      return;
    }
    if(S=='K' ){
      System.out.println("A");
      return;
    }
    if(S=='L' ){
      System.out.println("A");
      return;
    }
    if(S=='M' ){
      System.out.println("A");
      return;
    }    
    if(S=='N' ){
      System.out.println("A");
      return;
    }
    if(S=='O' ){
      System.out.println("A");
      return;
    }
    if(S=='P' ){
      System.out.println("A");
      return;
    }
    if(S=='Q' ){
      System.out.println("A");
      return;
    }
    if(S=='R' ){
      System.out.println("A");
      return;
    }
    if(S=='S' ){
      System.out.println("A");
      return;
    }
    if(S=='T' ){
      System.out.println("A");
      return;
    }
    if(S=='U' ){
      System.out.println("A");
      return;
    }
    if(S=='V' ){
      System.out.println("A");
      return;
    }
    if(S=='W' ){
      System.out.println("A");
      return;
    }
    if(S=='X' ){
      System.out.println("A");
      return;
    }
    if(S=='Y' ){
      System.out.println("A");
      return;
    }
    if(S=='Z' ){
      System.out.println("A");
      return;
    }
    
    System.out.println("a");


  }
  
}



Measured memory_bytes: 35692
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod = 1000000007;

int main() {
  int N;
  cin>>N;
  vector<int>B(N-1);
  int sum=0;
  for(int i=0;i<N-1;i++){
    cin>>B[i];
    if(i==0){sum+=B[i];}
    else{sum+=min(B[i],B[i-1]);}
  }
  sum+=B[N-2];
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3580
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<functional>
#include<iostream>
#define LL long long int
#define rep(i,n) for(LL i=0;i<n;i++)
#define F1 first
#define F2 second
#define INF 2000000000
using namespace std;
LL n,m,num;
LL dp[1010][1010],cost[1010],level[1010];
	
int main(void)
{	

	cin>>n>>m;
	rep(i,n) cin>>cost[i];
	rep(i,m) cin>>level[i];
	
	for(LL i=0;i<=m;i++)
		for(LL j=0;j<=n;j++) dp[i][j]=INF;
		
	//dp
	dp[0][0]=0;
	for(LL i=0;i<m;i++) {
		for(LL j=0;j<=n;j++){
			if(dp[i][j]!=INF) {
				num=level[i]*cost[j];
				dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
				if(j+1<=n)
					dp[i+1][j+1]=min(dp[i][j]+num,dp[i+1][j+1]);
			}
		}
	}
	
/*	for(LL i=0;i<=m;i++) {
		for(LL j=0;j<=n;j++) {
			printf("%5d",dp[i][j]);
		}
		cout<<endl;
	}*/
	cout<<dp[m][n]<<endl;
	
}

Measured memory_bytes: 10976
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int x[15] = { 0 };
	int ans = 0;
	int a, b, c;
	scanf("%d %d %d", &a,&b,&c);
	x[a]++;
	x[b]++;
	x[c]++;
	if (x[5] == 2 && x[7] == 1)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    vector<string> ans;
    ll n = s.size();
    rep(i, 0, n){
        if(i + t.size() - 1 >= n) continue;
        bool f = true;
        string tmp = s;
        rep(j, 0, t.size()){
            tmp[i + j] = t[j];
            if(s[i + j] != t[j] && s[i + j] != '?') f = false;
        }
        if(f) ans.push_back(tmp);
    }
    sort(ans.begin(), ans.end());
    if(ans.empty()) cout << "UNRESTORABLE" << endl;
    else{
        rep(i, 0, n){
            if(ans[0][i] == '?') ans[0][i] = 'a';
        }
        cout << ans[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val Array(n,a,b) = io.StdIn.readLine().split(' ').map(_.toLong)
  val x = n / (a + b)
  val c = (a+b) * x
  val d = if (c >= n) 0 else if (c+a <= n) a else n-c
  println(a*x+d)
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r = 0;
  rep(i,n) {
    if(s[i] == 'R') r++;
  }
  int ans = 0;
  rep(i,n) {
    if(s[i] == 'R' && i+1 > r) ans++;
  }
  cout << ans << endl;
}

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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    ll n,k,d;
    cin >> n >> k;
    ll a[n]={};
    for(int j=0;j<k;j++)
    {
        cin >> d;
        for(int i=0;i<d;i++)
        {
            ll x;
            cin >> x;
            a[x-1]=1;
        }
    }
    ll count=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


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


signed main() {
  string s; cin >> s;
  
  int ans = 0;
  int a = 0;
  int b = 0;
  
  rep(i, s.size()) {
    if(s[i] == 'A') {
      a++;
      b = 0;
    }
    else if(s[i] == 'B') {
      b++;
      if(i < s.size()-1 && s[i+1] != 'C') a = 0;
    }
    else {
      if(a > 0 && b == 1) {
        ans += a;
      } else {
        a = 0;
      }
      b = 0;
    }
  }
  
  
  cout << ans << endl;
}


Measured memory_bytes: 640
from collections import deque
h,w = map(int, input().split())

m = [list(input()) for _ in range(h)]

def get_start_points(m):
    start_points = []
    for y in range(h):
        for x in range(w):
            if m[y][x] == '#':
                start_points.append((y,x))
    return start_points

def bfs(start_points):
    que = deque(start_points)
    step = 0
    count_flag = False
    while len(que):
        for q in range(len(que)):
            y,x = que.popleft()
            for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]:
                ny = y + dy
                nx = x + dx
                if not (0<=ny<h and 0<=nx<w) or m[ny][nx] != '.':
                    continue
                m[ny][nx] = '#'
                count_flag = True
                que.append((ny,nx))

        if count_flag:
            step += 1
            count_flag = False
        else:
            break
    return step

print(bfs(get_start_points(m)))

Measured memory_bytes: 134224
from collections import Counter

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

B = []
s = 0
for a in A:
    s = (s+a)%M
    B.append(s)

C = Counter(B)

ans = 0
for k, n in C.items():
    if k == 0:
        ans += (n+1)*n//2
    else:
        ans += (n-1)*n//2
print(ans)

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 1e5;
int n, m, ans;
struct ufSet {
    int fa[MAXN + 5];

    inline void init() {
		for (int i = 1; i <= n; ++i) fa[i] = i;
	}
    int find(int x) {
		return x != fa[x] ? fa[x] = find(fa[x]) : x;
	}
    inline bool check(int x, int y) {
		return find(x) == find(y);
	}
    inline void merge(int x, int y) {
		fa[find(x)] = find(y);
	}
} s;

int main() {
	read(n), read(m);
	s.init();
	for (int u, v, w, i = 1; i <= m; ++i) {
		read(u), read(v), read(w);
		s.merge(u, v);
	}
	for (int i = 1; i <= n; ++i)
		if (s.fa[i] == i) ++ans;
	write(ans);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define ull unsigned long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define ull unsigned long long 
#define sc second
#define pb push_back
#define mp make_pair
#define sp <<" "
#define all(a) (a).begin(),(a).end()
#define fi(i,a,n) for(int i=a ; i<n ; i++)
#define fd(i,n,a) for(int i=n-1 ; i>=a ; i--)
#define r0 return 0;
#define ln "\n"
#define INF (int)1e15
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   
void solve(){
    
}
int main(){
	fast
    // ll t;cin>>t;
    // while(t--) solve();
    ll t;cin>>t;
    vector<int>x(t),y(t);
    for(int i=0;i<t;i++){
        cin>>x[i];
        cin>>y[i];
    }
    int res = 0, n = x.size(), smallest, cur;
        for (int p : {1, -1}) {
            for (int q : {1, -1}) {
                smallest = p * x[0] + q * y[0] + 0;
                for (int i = 1; i < n; ++i) {
                    cur = p * x[i] + q * y[i] ;
                    res = max(res, cur - smallest);
                    smallest = min(smallest, cur);
                }
            }
        }
        cout<<res;
	r0;
}


Measured memory_bytes: 4684
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  map<int, int> mp;
  vector<int> a(n);
  REP(i, n) {
    cin >> a[i];
    ++mp[a[i]];
  }
  REP(i, n) {
    --mp[a[i]];
    if (mp[a[i]] == 0) mp.erase(a[i]);
    cout << (*mp.rbegin()).first << '\n';
    ++mp[a[i]];
  }
  return 0;
}


Measured memory_bytes: 7936
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int count=0;
        while(n!=0)
        {
            int a = scn.nextInt();
            int b = scn.nextInt();
            if(a==b)
            {
                count++;
            }
            else if(count<3)
            {
                count=0;
            }
            n--;
        }
        if(count>=3)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 36036
#![allow(non_snake_case, unused_imports)]

// Input macros
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)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $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, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,VecDeque,BinaryHeap};

// Functions

// Main
fn main(){

    input!{
        A: usize,
        B: usize
    }

    let mut ans = 0;
    for i in A..B+1{
        let s = i.to_string();
        if s == s.chars().rev().collect::<String>(){
            ans += 1;
        }
    }

    println!("{}", ans);
}

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

using namespace std;
using ll = long long;

int main(){
  ll n,i,j;
  cin >> n;
  vector<ll> v(n);
  for(i=0;i<n;i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  ll sum=0;
  for(i=0;i<n;i++){
    sum+=abs(v[i]);
  }
  vector<pair<ll,ll>> vp;
  if(v[0]<0&&v.back()>=0){
    for(i=0;i<n;i++){
      if(v[i]>=0)break;
    }
    for(j=i;j<n-1;j++){
      vp.push_back({v[0],v[j]});
      v[0]-=v[j];
    }
    for(j=0;j<i;j++){
      vp.push_back({v.back(),v[j]});
      v[n-1]-=v[j];
    }
  }else if(v[0]>=0){
    sum-=2*v[0];
    for(j=1;j<n-1;j++){
      vp.push_back({v[0],v[j]});
      v[0]-=v[j];
    }
    vp.push_back({v.back(),v[0]});
  }else {
    for(j=0;j<n-1;j++){
      vp.push_back({v.back(),v[j]});
      v[n-1]-=v[j];
    }
    sum=v.back();
  }
  cout << sum <<  endl;
  for(auto x:vp){
    cout << x.first << " " << x.second << endl;
  }
  return 0;
}


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

int main(){
  
  while(1){
    int n,p;
    int May_wan[50];
    int i,ans;

  cin >> n >> p;
  int p_max = p;
  if(n == 0&&p == 0)break;
  for(int i = 0; i < 50; i++)May_wan[i] = 0;
   i =0,ans = 0;
  while(1){
    if(p_max == May_wan[i]){
      ans = i;
      break;
}    
    if(p > 0){
      May_wan[i]++;
      p--;
    }

    else if(p == 0){
      p+=May_wan[i];
      May_wan[i] = 0;
    }
    

    if(i == n-1)i = 0;
    else i++;
  }
  cout << i << endl;
  }
return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

void swap(int *x, int *y){
        int tmp;
        tmp = *x;
        *x = *y;
        *y = tmp;
}

int main(){
        int K, N;
        int price[1000];
        int i, j;
        int sum = 0;
        scanf("%d %d", &N, &K);
        for(i = 0; i < N; i++){
                scanf("%d", &price[i]);
        }

        for(i = 0; i < N - 1; i++){
                for(j = 1; j < N - i; j++){
                        if(price[j - 1] > price[j]){
                                swap(&price[j - 1], &price[j]);
                        }
                }
        }
        for(i = 0; i < K; i++){
                sum += price[i];
        }
        printf("%d\n", sum);
        return 0;
}

Measured memory_bytes: 1724
n,m = map(int, raw_input().split(' '))
def intersection(A,B):
	a,b  = max(A[0],B[0]), min(A[1],B[1])
	return [a,b] if a <= b else []

r = [1,n]
for _ in range(m):
	a,b = map(int, raw_input().split(' '))
	r = intersection(r, [a,b])
	if len(r) == 0: break
print (r[1] - r[0] + 1) if r else 0


Measured memory_bytes: 33640
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: isize = iterator.next().unwrap().parse().unwrap();

    for a in 0..1000 {
        for b in 0..1000 {
            let a5: isize = a * a * a * a * a;
            let b5: isize = b * b * b * b * b;
            if a5 - b5 == x {
                return format!("{} {}", a, b);
            }
            if (-a5) - b5 == x {
                return format!("{} {}", -a, b);
            }
            if a5 - (-b5) == x {
                return format!("{} {}", a, -b);
            }
            if (-a5) - (-b5) == x {
                return format!("{} {}", -a, -b);
            }
        }
    }

    return String::new();
}


Measured memory_bytes: 2048
use std::io::*;
use std::str::FromStr;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
#[allow(non_snake_case, unused_variables)]
fn main() {
    let S: Vec<char> = read::<String>().chars().collect();
    let mut ans = "No";
    if S.len()>=4 && S[0]=='Y' && S[1]=='A' && S[2]=='K' && S[3]=='I' {
        ans = "Yes";
    }
    println!("{}", ans);
}




Measured memory_bytes: 4352
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double[] v = new double[N];
     for(int i = 0; i < N; i++) {
        	v[i] = sc.nextDouble();
        }
      
        

        Arrays.sort(v);
      
      double sum1 = (v[0] + v[1])/2;
        
        if(N < 3) {
        	System.out.println(sum1);
        }else {
        	for(int i = 2; i < N; i++) {
            	sum1 = (sum1 + v[i])/2;
            }
            
            System.out.println(sum1);
        }
        
        sc.close();
    }
}


Measured memory_bytes: 23380
def RSQ_add(i, x):
    while True:
        if i > n:
            break
        b[i] += x
        i += i & -i

def RSQ_getsum(i):
    s = 0
    while True:
        if i <= 0:
            break
        s += b[i]
        i -= i & -i
    return s

n, q = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(n):
    RSQ_add(i + 1, a[i])
for _ in range(q):
    x, y, z = map(int, input().split())
    if x == 0:
        RSQ_add(y + 1, z)
    else:
        ans = RSQ_getsum(z) - RSQ_getsum(y)
        print(ans)

Measured memory_bytes: 132232
import java.util.*;
import java.io.*;
class Main {
    static class Triplet {
        long x, y;
        int z;
        Triplet(long x, long y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }
    static long MOD = (long)(1e9+7);
    static long[] segTree;
    static void update(int node, int left, int right, int idx, long value) {
        if(left>right)
            return;
        if(left==right && idx==left) {
            segTree[node] = value;
            return;
        }
        int mid = left + (right-left)/2;
        if(idx<=mid)
            update(2*node+1, left, mid, idx, value);
        else update(2*node+2, mid+1, right, idx, value);
        segTree[node] = Math.max(segTree[2*node+1], segTree[2*node+2]);
    }
    static long query(int node, int left, int right, int start, int end) {
        if(left>right || left>end || right<start)
            return 0;
        if(left>=start && right<=end)
            return segTree[node];
        int mid = left + (right-left)/2;
        long q1 = query(2*node+1, left, mid, start, end);
        long q2 = query(2*node+2, mid+1, right, start, end);
        return Math.max(q1, q2);
    }
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] heights = new long[n];
        long[] beauties = new long[n];
        for(int i = 0; i<n; i++)
            heights[i] = sc.nextLong();
        for(int i = 0; i<n; i++)
            beauties[i] = sc.nextLong();
        Triplet[] triplets = new Triplet[n];
        segTree = new long[4*n];
        for(int i = 0; i<n; i++)
            triplets[i] = new Triplet(heights[i], beauties[i], i);
        Arrays.sort(triplets, (a, b)->Long.compare(a.x, b.x));
        for(int i = 0; i<n; i++) {
            Triplet curr = triplets[i];
            long height = curr.x;
            long beauty = curr.y;
            int idx = curr.z;
            long ans = beauty;
            if(idx!=0) {
                long q = query(0, 0, n-1, 0, idx-1);
                ans+=q;
            }
            update(0, 0, n-1, idx, ans);
        }
        System.out.println(query(0, 0, n-1, 0, n-1));
    }
}

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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  long long ans = 0;
  while(true){
    for(int i = 0; i < n; i++){
      if(a[i] % 2 != 0){
        cout << ans << endl;
        return 0;
      }
      a[i] /= 2;
    }
    ans++;
  }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

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

    for(int i=10;i<10010;i++){
        if(int(i*0.08) == a &&  b== int(i*0.1)){
            cout << i;
            return 0;
        }
        
    }
    
    cout << "-1";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <cmath>
#define rep(i, a, n) for(int i = a;i < n;i++)
using namespace std;


using P = pair<int, int>;


int n;
int t[100010];
P p[100010];


bool solve(){
	bool b;
	rep(i, 1, n+1){
		int T = t[i]-t[i-1];
		int d = abs((p[i].first-p[i-1].first)) + abs((p[i].second-p[i-1].second));
		int v = T-d;
		
		if(v >= 0 && v % 2 == 0) b = true;
		else b = false;

		if(b) continue;
		else return false;
	}
	return true;
}

int main(){
	cin >> n;
	rep(i, 1, n+1) cin >> t[i] >> p[i].first >> p[i].second;

	if(solve()) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

using namespace std ;

const int MAX = 2e5 + 10 ;

int vis[MAX] ;
int n , m ;

vector< vector<int> >adj(MAX) ;

int cnt = 0 ;

void dfs(int node)
{
	cnt++ ;
	vis[node] = 1 ;
	for(auto &child : adj[node])
	{
		if(vis[child])
			continue ;
		dfs(child) ;
	}
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i < m ; ++i)
	{
		int x , y ;
		cin>>x>>y ;
		adj[x].push_back(y) ;
		adj[y].push_back(x) ;
	}
	int ans = 0 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		if(vis[i])
			continue ;
		cnt = 0 ;
		dfs(i) ;
		ans = max(ans , cnt) ;
	}
	return cout<<ans<<"\n" , 0 ;
}		

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

#define LL long long
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define LEN(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

int n,m,ans=0;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >>n >>m;
	ans+=n*(n-1)/2;
	ans+=m*(m-1)/2;
	cout <<ans;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 256
char*C="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?",*strchr(),*L="68443586484588538455886888366866";
unsigned char B[]={
	0x25,0x9a,0x05,0x01,0x06,0x09,0x9b,0x10,0x07,0x98,0x06,0x04,0x99,0x9e,0x05,0x07,
	0x9f,0x08,0x06,0x07,0x9c,0x9d,0x02,0x92,0x93,0x90,0x05,0x11,0x03,0x91,0x00,0x01
};
b,l;
main(c){
	for(;c=getchar(),c+1;)
		if(c-10)
			for(c=strchr(C,c)-C,b=b<<(L[c]-48)|B[c],l+=L[c]-48;l>4;putchar(C[b>>l&31]))
				l-=5;
		else l&&putchar(C[(b<<=5-l)&31]),l=0,putchar(c);
	exit(0);
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>

int main(void)
{
    int i,n;
        double x,mean,poi[1010]={0};
    
    while(scanf("%d",&n)){
        x=0;
        if(n!=0){
        for(i=0;i<n;i++){
            scanf("%lf",&poi[i]);
            x+=poi[i];
        }
        mean=x/n;
        x=0;
        
        for(i=0;i<n;i++){
            x+=pow(poi[i]-mean,2);
        }
        
        mean=sqrt(x/n);
        printf("%f\n",mean);
        }else break;
    }
    return 0;
}


Measured memory_bytes: 2132
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.ST                 as ST
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n $ BS.unpack <$> BS.getLine
toPair [x, y] = (x, y)

main = do
  [n] <- readInt
  x   <- readInt
  print $ solve x

solve :: [Int] -> Int
solve xs = foldl' (\acc x -> acc + (x - a xs) ^ 2) 0 xs

a :: [Int] -> Int
a x = round $ fromIntegral (sum x) / fromIntegral (length x)



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

using namespace std;

#define ll long long
#define pb push_back

ll n, a[999999], ans;

int main () {

cin >> n;

for (int i = 1; i <= 3 * n; ++i) {
    cin >> a[i];
}

sort(a + 1, a + 1 + 3 * n);

for (int i = n + 1; i <= 3 * n; i += 2){
    ans += a[i];
}

cout << ans;

return 0;

}


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

#define sd(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ll long long
#define N 310

int a[N][N], mark[N], freq[N];
int main()
{
	int n,m,i,j,k;
	sd(n);sd(m);
	int ans = N;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			sd(a[i][j]);
	clr(mark);
	for(k=1;k<=m;k++)
	{
		clr(freq);
		for(i=1;i<=n;i++)
		{
			for(j=1;mark[a[i][j]]==1;j++);
			freq[a[i][j]]++;
		}
		int maxx=0,maxi;
		for(i=1;i<=m;i++)
			if(freq[i]>maxx)
			{
				maxx=freq[i];
				maxi=i;
			}
		ans=min(ans,maxx);
		mark[maxi]=1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <vector>
#include<algorithm>

using namespace std;

int main()
{
	int X, A, B;
	cin >> X >> A >> B;

	if (A - B >= 0)
		cout << "delicious" << endl;
	else if (B - A <= X)
		cout << "safe" << endl;
	else
	cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    string s; getline(cin, s);
    cout << (s[0] == s[2] ? "H\n" : "D\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int X, A, B;
  cin >> X >> A >> B;
  cout << (X - A) % B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int n,m;
int a[100010];
pair<int,int> p[100010];
ll ans;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++){
		cin>>p[i].second>>p[i].first;
	}
	sort(a,a+n);
	sort(p,p+m);
	int pos1=n-1;
	int pos2=m-1;
	int cnt=0;
	while(cnt<n){
		cnt++;
		if(p[pos2].second==0 && pos2!=0)pos2--;
		int num1=a[pos1];
		int num2=p[pos2].first;
		if(pos2==0 && p[pos2].second==0)num2=-1;
		if(num1>=num2 ){
			ans+=num1;
			pos1--;
		}
		else{
			ans+=num2;
			p[pos2].second--;
		}
	}
	cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>

using namespace std;

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

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

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

    

    if (N % 2) {
        long long ans1 = 0, ans2 = 0;
        int K = N / 2;
        for (int i = 0; i < K-1; i++) {
            ans1 += 2 * a[N - 1 - i];
        }
        ans1 += a[N - 1 - K + 1] + a[N - 1 - K];
        for (int i = 0; i < K; i++) {
            ans1 -= 2*a[i];
        }

        for (int i = 0; i < K; i++) {
            ans2 += 2 * a[N - 1 - i];
        }
        ans2 -= (a[N - 1 - K] + a[N - 1 - K - 1]);
        for (int i = 0; i < K - 1; i++) {
            ans2 -= 2*a[i];
        }
        cout << max(ans1, ans2);
    }
    else {
        long long ans = 0;
        int K = N / 2;
        for (int i = 0; i < K - 1; i++) {
            ans += 2 * (a[N - 1 - i] - a[i]);
        }
        ans += a[K] - a[K - 1];
        cout << ans << endl;
    }
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main() {
  int k, s;
  cin >> k >> s;
  
  int res = 0;
  for (int i=0; i<=k; i++) {
    for (int j=0; j<=k; j++) {
      int tmp = s - i - j;
      if (tmp >= 0 && tmp <= k) {
        res++;
      }
    }
  }
  
  cout << res << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll kaizyo(ll k) {
  ll sum = 1;
  FOR(i, 1, k + 1) sum = sum * i % mod;
  return sum ;
}

signed main() {
	ll n, m, result = 0;
  cin >> n >> m;
  if (n == m) result = 2 * kaizyo(n) * kaizyo(m) % mod;
  else if (abs(n - m) == 1) result = kaizyo(n) * kaizyo(m) % mod;
  else result = 0;
  cout << result << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        String line = sc.next();

        String[] lines = line.split("");

        if(lines.length > K){
            for(int i = 0; i < K; i++){
                System.out.print(lines[i]);
            }
            System.out.print("...");
//            System.out.println();
        }else{
            System.out.println(line);
        }
    }
}


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

int main(){
    int n; //n+1回跳ねる
    int x; //xは座標
    cin >> n >> x;

    int sum = 0; //今いる座標
    int ans = 1; //0は必ず含まれるので１
    int l; //跳ねる距離
    for(int i=0; i<n; i++){
        cin >> l;
        sum += l;
        if(sum > x) break;
        ans += 1;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
function main()
  
  (N,X) = map(x -> parse(Int,x), split(readline()))
  x = map(x -> parse(Int,x), split(readline()))
  
  ans = abs(X-x[1])
  
  for i in 2:N
    ans = gcd(ans,abs(X-x[i]))
  end
  
  println(ans)
  
end

main()

Measured memory_bytes: 131056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1000000007;

int main(){
  int N,M;cin >> N >> M;
  int sum=0;
  for(int i=0;i<M;i++){
    int x;cin >> x;
    sum += x;
  }
  if(N<sum){
    cout << -1 << endl;
  }else{
    cout << N-sum << endl;
  }
}

Measured memory_bytes: 3676