akhauriyash/Code-Regression huggingface dataset:
import scala.util.Try

object Main {

  def calc(e: String, i: Long, j: Long): Long =
    e match {
      case "+" => j + i
      case "-" => j - i
      case "*" => j * i
      case _ => throw new IllegalArgumentException()
    }

  def main(args: Array[String]) : Unit = {
    val stack: Seq[Long] = scala.io.StdIn.readLine().split(" ")
                           .foldLeft(List[Long]()) { (list, elem) =>
                             Try(elem.toLong).getOrElse(elem) match {
                               case e: Long => e +: list
                               case e: String => calc(e, list(0), list(1)) +: list.drop(2)
                               case _ => throw new IllegalArgumentException()
                             }
                           }
    println(stack.head)
  }
}



Measured memory_bytes: 43768
#include <stdio.h>
#include <ctype.h>
 
int P,Q,R;
char *p;
 
int formula(){
    int l,r;
    char c = *p++;
    if(isdigit(c)) return c-'0';
    if(isupper(c)) return (c == 'P' ? P : c == 'Q' ? Q : R);
    if(c == '-') return 2-formula();
    if(c == '('){
	l = formula();
	if(*p++ == '*'){
	    r = formula();
	    *p++;
	    return (l < r ? l : r);
	}else{
	    r = formula();
	    *p++;
	    return (l > r ? l : r);
	}  
    }
    return 0;
}
 
int main(){
    int ans;
    char s[100];
    while(scanf("%s",s), s[0] != '.'){
	ans = 0; 
	for(P = 0 ; P < 3 ; P++){
	    for(Q = 0 ; Q < 3 ; Q++){
		for(R = 0 ; R < 3 ; R++){
		    p = s;
		    if(formula() == 2) ans++;
		}
	    }
	}
	printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 2572
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ans = 0;
    while(true){
      int n = a*ans - (ans-1);
      if(n >= b){
        System.out.println(ans);
        break;
      }
      ans++;
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    ll N,K,S;
    cin >> N >> K >> S;
    vector<ll> ans;
    ll a=1;
    ll b=S-1;

    for(ll i = 0; i < N; i++){
        if(i<K){
            ans.push_back(S);  
        }else{
            if(S!=1000000000){
                ans.push_back(1000000000);
            }else{
                ans.push_back(1);
            }           
        }
    }
    for(ll i = 0; i < N; i++){
        cout << ans[i];
        if(i!=N-1) {
            cout << " ";
        }else{
            cout << endl;
        }
        
    }


}

Measured memory_bytes: 2292
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let (N, K): (usize, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let A: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let MOD = 1_000_000_007;
    let K_1 = ((K * (K + 1)) / 2) % MOD;
    let K_2 = ((K * (K - 1)) / 2) % MOD;
    let ans = {
        let mut res = 0;
        for i in 0..N {
            let mut x = 0;
            for j in (i + 1)..N {
                if A[i] > A[j] {
                    x += 1;
                }
            }
            let mut y = 0;
            for j in 0..i {
                if A[i] > A[j] {
                    y += 1;
                }
            }
            x = (x * K_1) % MOD;
            y = (y * K_2) % MOD;
            res = (res + x) % MOD;
            res = (res + y) % MOD;
        }
        res
    };

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


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

using namespace std;

#define int long long
#define reg register
#define Raed Read
#define clr(a,b) memset(a,b,sizeof a)
#define Mod(x) (x>=mod)&&(x-=mod)
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)
#define erep(i,G,x) for(int i=(G).Head[x]; i; i=(G).Nxt[i])
#pragma GCC target("avx,avx2,sse4.2")
#pragma GCC optimize(3)

inline int Read(void) {
	int res=0,f=1;
	char c;
	while(c=getchar(),c<48||c>57)if(c=='-')f=0;
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>=48&&c<=57);
	return f?res:-res;
}

template<class T>inline bool Min(T &a, T const&b) {
	return a>b?a=b,1:0;
}
template<class T>inline bool Max(T &a, T const&b) {
	return a<b?a=b,1:0;
}
const int N=1e3+5,M=1e5+5;

bool MOP1;

int A[N][N],K[N],P[N],Q1[N],l1,r1,Q2[N],l2,r2;

bool MOP2;

void _main(void) {
//	cerr<<"M="<<(&MOP2-&MOP1)/1024.0/1024.0<<endl;
	int n=Read(),w=n*(n-1)/2;
	rep(i,1,n) {
		P[i]=1,Q1[++r1]=i;
		ret(j,1,n)A[i][j]=Read();
	}
	int Ans;
	for(Ans=1;; ++Ans) {
		int f=0,v=0;
		clr(K,0);
		if(!(Ans&1)) {
			r1=0;
			rep(i,1,r2) {
				int x=Q2[i];
				if(!K[x]&&P[x]<n) {
					int p=A[x][P[x]];
					if(!K[p]&&A[p][P[p]]==x)++P[x],++P[p],K[x]=K[p]=f=1,--w,Q1[++r1]=x,Q1[++r1]=p;
				}
			}
		} else {
			r2=0;
			rep(i,1,r1) {
				int x=Q1[i];
				if(!K[x]&&P[x]<n) {
					int p=A[x][P[x]];
					if(!K[p]&&A[p][P[p]]==x)++P[x],++P[p],K[x]=K[p]=f=1,--w,Q2[++r2]=x,Q2[++r2]=p;
				}
			}
		}
		if(!w)break;
		if(!f) {
			puts("-1");
			return;
		}
	}
	printf("%d\n",Ans);
}

signed main() {
	_main();
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	int a[3][3];
	bool b[3][3];
	memset(b,0,sizeof(b));
	int n;
	REP(i,3)
		REP(j,3)
			cin>>a[i][j];
	cin>>n;
	REP(i,n)
	{
		int c;
		cin>>c;
		REP(j,3)
			REP(k,3)
				if(a[j][k]==c)b[j][k]=1;
	}
	bool flag=0;
	REP(i,3)
	{
		if(b[i][0]&&b[i][1]&&b[i][2])flag=1;
		if(b[0][i]&&b[1][i]&&b[2][i])flag=1;
	}
	if(b[0][0]&&b[1][1]&&b[2][2])flag=1;
	if(b[0][2]&&b[1][1]&&b[2][0])flag=1;
	if(flag)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}



Measured memory_bytes: 256
n, h = gets.split.map(&:to_i)

a = Array.new(n)
b = Array.new(n)
n.times do |i|
  a[i], b[i] = gets.split.map(&:to_i)
end

a.sort!
b = b.sort.reverse

# p [a, b]
# p a.max

ans = 0
i = n
j = n

m = a.max

b.each do |b_|
  
  break if m > b_
  
  h -= b_
  ans += 1
  if h <= 0
    puts ans
    exit
  end
end

# p [ans, h, m]

puts ans + (h + m - 1 ) / m

# p 500-b.inject(:+)
# p 5 + (189*1.0 + 46 - 1) / 46
# p 189 % 46
# p 46 * 4
# p 46 * 5
# p 189 + 46 - 1

Measured memory_bytes: 4968
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

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


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll k;
    cin >> k;
    queue<ll> q;
    REP(i, 1, 10) q.push(i);
    ll count = 0;
    while(!q.empty()){
        ll num = q.front();
        count++;
        if(count == k){
            print(num);
            return 0;
        }
        q.pop();
        ll rem = num % 10;
        if(rem - 1 >= 0) q.push(num * 10 + rem - 1);
        q.push(num * 10 + rem);
        if(rem + 1 <= 9) q.push(num * 10 + rem + 1);
    }




}

Measured memory_bytes: 4752
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
vector<int> m[100005];
int n,u,v;
int dfs(int pos,int pre){
    int len=m[pos].size(),ans=0;
    for(int i=0;i<len;i++)
        if(m[pos][i]!=pre) ans+=dfs(m[pos][i],pos);
	if(ans>=2){
        printf("First\n");
        exit(0);
    }
    else if(ans==0) return 1;
    else return 0;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        m[u].push_back(v);
        m[v].push_back(u);
    }
    if(dfs(1,-1)) printf("First\n");
    else printf("Second\n");
    return 0;
}

Measured memory_bytes: 5888
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef std::vector<ll> lls;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 998244353L;
template<class T> inline void chmin(T& a, T b) { if (a > b) a = b; }
template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }
template<class T> inline T MaxE(vector<T>& v, ll S, ll E) { T m = v[S]; for (ll i = S; i <= E; i++)chmax(m, v[i]); return m; }//v[S]～v[E]の最大値
template<class T> inline T MinE(vector<T>& v, ll S, ll E) { T m = v[S]; for (ll i = S; i <= E; i++)chmin(m, v[i]); return m; }
template<class T> inline T MaxE(vector<T>& v, ll N) { return MaxE(v, 0, N - 1); } //先頭N個中の最大値
template<class T> inline T MinE(vector<T>& v, ll N) { return MinE(v, 0, N - 1); } //先頭N個中の最小値
template<class T> inline T MaxE(vector<T>& v) { T m = v[0]; for (T e : v)chmax(m, e); return m; }
template<class T> inline T MinE(vector<T>& v) { T m = v[0]; for (T e : v)chmin(m, e); return m; }


void cinv(lls& llVec, ll n, bool to_0_origin = false) {
	ll val;
	llVec.reserve((size_t)(n));
	for (ll i = 0; i < n; i++) {
		cin >> val;
		if (to_0_origin) val--;
		llVec.push_back(val);
	}
}

ll rec(ll v, std::vector<lls> &G, lls &tbl) {
	if (tbl[v] != -INF) return tbl[v];

	ll maxval = 0;
	for (auto vv : G[v]) {
		chmax(maxval, rec(vv,G,tbl) + 1);
	}
	tbl[v] = maxval;
	return maxval;
}

int main()
{
	ll N, M;
	cin >> N >> M;
	std::vector<lls> G(N);

	for (ll i = 0; i < M; i++) {
		ll xx, yy;
		cin >> xx >> yy;
		xx--; yy--;
		G[xx].push_back(yy);
	}

	//テーブル初期化
	lls tbl(N, -INF);

	//メモ化再帰
	ll maxval = -INF;
	for (ll v = 0; v < N; v++) {
		chmax(maxval, rec(v, G, tbl));
	}

	cout << maxval << '\n';

	return 0;
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
bool strRev(string str)
{
    string stR = str;
    reverse(stR.begin(), stR.end());
    if(str == stR)
    {
        return true;
    }
    else
    {
        return false;
    }

}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    int sl1 = ((len - 1)/2);
    int sl2 = (len + 3)/2;
    //cout << len << endl;
    //cout << sl1 << endl;
   // cout << sl2 << endl;
    string sub1 = s.substr(0, sl1);
    string sub2 = s.substr(sl2-1, len-1);
   // cout << sub1 << endl;
    //cout << sub2 << endl;
    if(strRev(s) == true && strRev(sub1) == true && strRev(sub2) == true)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int n, m, t;
int main()
{
    //freopen("test.inp","r", stdin);
    cin >> n >> m;
    t = 0;
    for (int i = 2; i <= n; i++) t += i-1;
    for (int i = 2; i <= m; i++) t += i-1;
    cout << t;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(c) sort((c).begin(),(c).end())
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define reprs(i, m, n) for(int i = n; i >= m; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main(){

  int N,D;
  cin >> N >>D;
  cout << (N+(1+2*D)-1)/(1+2*D) <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define go(i, a, n) for (ll i = a; i < (ll)n; i++)
#define gor(i, a, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define gos(i, a, n, step) for (ll i = a; i < (ll)n; i += step)
#define show(a) cout << a << '\n'
#define show2(a, b) cout << a << " " << b << '\n'
#define show3(a, b, c) cout << a << " " << b << " " << c << '\n'
#define show4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << '\n'
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod 1000000007
#define mem(a, k) memset(a, k, sizeof(a))
#define answer(z, k) cout << "Case #" << z << ": " << k << endl;
auto t1 = chrono::high_resolution_clock::now();
class student
{
public:
    string name, rno;
    float marks;
    ll index;
};
bool cmp(student a, student b)
{
    if (a.marks == b.marks)
        return a.index < b.index;
    return a.marks < b.marks;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    if (n >= 30)
        show("Yes");
    else
        show("No");
    auto t2 = chrono::high_resolution_clock::now();
    auto duration = chrono::duration_cast<chrono::milliseconds>(t2 - t1).count();
    clog << "Time taken = " << duration * 1.0 / 1000 << " seconds" << endl;
    return 0;
}

Measured memory_bytes: 3796
EPS = 1e-9
class Point
  attr_accessor :x, :y 
  def initialize p
    @x = p[0]
    @y = p[1]
  end
end
def cross(p1,p2,p3,p4)
  a = (p4.y - p3.y)*(p4.x - p1.x) - (p4.x - p3.x)*(p4.y - p1.y)
  b = (p2.x - p1.x)*(p4.y - p1.y) - (p2.y - p1.y)*(p4.x - p1.x)
  c = (p2.x - p1.x)*(p4.y - p3.y) - (p2.y - p1.y)*(p4.x - p3.x)
  return nil if c.abs < EPS
  d = a / c
  e = b / c
  return nil if d < 0 || d > 1 || e < 0 || e > 1
  Point.new([(p2.x - p1.x) * d + p1.x, (p2.y - p1.y) * d + p1.y])
end
while gets
  break if $_.strip == "0 0 0 0"
  l1 = $_.split.map(&:to_f)
  l2 = gets.split.map(&:to_f)
  l3 = gets.split.map(&:to_f)
  p1 = Point.new(l1[0,2])
  p2 = Point.new(l1[2,2])
  p3 = Point.new(l2[0,2])
  p4 = Point.new(l2[2,2])
  p5 = Point.new(l3[0,2])
  p6 = Point.new(l3[2,2])

  c1 = cross(p1,p2,p3,p4)
  c2 = cross(p3,p4,p5,p6)
  c3 = cross(p5,p6,p1,p2)

  if !c1 || !c2 || !c3 || (c2.x - c1.x).abs < EPS && (c2.y - c1.y).abs < EPS
    puts "kyo"
  else
    s = ((c2.x - c1.x)*(c3.y - c1.y) - (c2.y - c1.y)*(c3.x - c1.x)).abs / 2
    if s >= 1_900_000 then puts "dai-kichi"
    elsif s >= 1_000_000 then puts "chu-kichi"
    elsif s >= 100_000 then puts "kichi"
    else puts "syo-kichi"
    end
  end
end

Measured memory_bytes: 8684
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0

for i in range(0, a + 1):
    for j in range(0, b + 1):
        for k in range(0, c + 1):
            sum = 500 * i + 100 * j + 50 * k

            if sum == x:
                ans += 1
            elif sum > x:
                break;


print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, P;
	
	cin>>A>>P;
	
	
	cout<<(A*3 + P)/2<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

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

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    ll N, X;
    cin >> N >> X;
    vector<ll> B(N), L(N), U(N), S(N);
    for (int n = 0; n < N; ++n) {
        cin >> B[n] >> L[n] >> U[n];
        S[n] = B[n]*L[n]+(X-B[n])*U[n];
    }
    vector<ll> I(N);
    for (int n = 0; n < N; ++n) I[n] = n;
    sort(I.begin(), I.end(), [&](int l, int r){ return S[l] > S[r]; });
    vector<ll> Ind(N);
    for (int n = 0; n < N; ++n) Ind[I[n]] = n;
    sort(S.begin(), S.end(), greater<ll>());
    vector<ll> Sum(N+1);
    Sum[0] = 0;
    for (int n = 1; n <= N; ++n) Sum[n] = Sum[n-1]+S[n-1];
    ll TargetS = 0;
    for (int n = 0; n < N; ++n) {
        TargetS += L[n]*B[n];
    }
    
    ll l = -1, r = X*N;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        ll Max = 0;
        
        ll q = m / X;
        ll r2 = m % X;
        for (int n = 0; n < N; ++n) {
            ll Tmp = r2 < B[n] ? r2*L[n] : B[n]*L[n]+(r2-B[n])*U[n];
            Tmp += Sum[q];
            if (Ind[n] < q) {
                Tmp -= S[Ind[n]];
                Tmp += S[q];
            }
            if (Max < Tmp) Max = Tmp;
        }
        
        if (Max >= TargetS) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << endl;

    return 0;
}


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

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

    for (auto k = 0; k < B; k++)
    {
        if ((k * A) % B == C)
        {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a;
    scanf("%d", &a);
    int h[a];
    int i, j, k, l = 0;
    for (i = 0; i < a; i++)
    {
        k = 0;
        scanf("%d", &h[i]);
        for (j = 0; j < i; j++)
        {
            if (h[i] >= h[j])
            {
                k++;
            }
        }
        if (k == i)
        {
            l++;
        }
    }
    printf("%d\n", l);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define chmax(x,y) x = max(x, y)

int main() {
    int n, W ;
    cin >> n >> W ;
    int dp[105][10005] ;
    int w [n] ;
    int v [n] ;
    rep(i, n){
        cin >> v[i] >> w[i] ;
    }
    rep(i, n){
        rep(j, W+1){
            if(j < w[i]){
                dp[i+1][j] = dp[i][j] ;
            }
            else {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i])  ;
            }
        }
    }
    cout << dp[n][W] << endl ; 
} 


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

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

    ll minval, maxval;
    ll sumval=0;
    if (k > n) {
        cout << "1" << endl;
    } else {
        for (ll i=k;i<=n;i++) {
            minval = (i-1)*i/2;
            maxval = (2*n-i+1)*i/2;
            sumval += (maxval - minval + 1);
            if (sumval > 1000000000+7) {
                sumval %= (1000000000+7);
            }
        }
        sumval++;
        cout << sumval << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
N = int(input())
A = input()
B = input()
C = input()

count = 0
def count_dif(s, t, u):
    x = list(set([s, t, u]))
    return len(x)

for i in range(N):
    d = count_dif(A[i], B[i], C[i])
    count += d-1

print(count)


Measured memory_bytes: 3060
/**
*	created: 29.08.2020 20:57:21
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

signed main() {
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    int ans = m;
    rep(i,n-m+1) {
        int cnt = 0;
        string sb = s.substr(i,m);
        rep(j,m) if (t[j] != sb[j]) cnt++;
        chmin(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
import sys
import collections
import math
from collections import Counter
from collections import deque


N, M = [int(x) for x in input().split()]

scc = 0
n = N
m = M

scc = min(n, m // 2)

n = n - scc
m = m - 2 * scc

if m >= 4:
    scc += (m // 4)

print(scc)
sys.exit(0)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
 
int main(){
  int n,a,b;
  cin >> n>> a >> b;
  int count=0;
  rep(i,n){
    int m=i+1;
    int sum=0;
    if(m==10000)sum=1;
    else if(m<=9999 && m>=1000){
      sum+=m/1000;
      m%=1000;
      sum+=m/100;
      m%=100;
      sum+=m/10;
      m%=10;
      sum+=m;
    }
    else if(m<=999 && m>=100){
      sum+=m/100;
      m%=100;
      sum+=m/10;
      m%=10;
      sum+=m;
    }
    else if(m<=99 && m>=10){
      sum+=m/10;
      m%=10;
      sum+=m;
    }
    else if(m<=9 && m>=1){
      sum=m;
    }
    if(sum<=b && sum>=a){
      count+=i+1;
    }
  }
  cout << count << endl;
      
}

Measured memory_bytes: 256
import java.io.IOException; 
import java.io.InputStream; 
import java.io.PrintWriter; 
import java.lang.StringBuilder;
import java.util.Arrays;

class Main{ 

	static void solve(){ 
		int n = ni(), k=ni();
		char[] sarr =ns().toCharArray();
		StringBuilder BA = new StringBuilder();
		for(int i=0;i<=n/2;++i)BA.append("BA");
		StringBuilder  ans = new StringBuilder();
		boolean rev = false;
		int index=0;
		char[] revc = new char[256];
		revc['A']='B';
		revc['B']='A';
		if(n==1){
			if(k%2==0)out.println(sarr[0]);
			else out.println(revc[sarr[0]]);
			return;
		}
		for(;index<n;++index){
			if(k==0)break;
			if((!rev&&sarr[index]=='A') || (rev&&sarr[index]=='B')){
				--k;sarr[index]=revc[sarr[index]];
			}
			if(k==0)break;
			rev=!rev;
			--k;
		}

		for(;index<n;++index){
			if(rev)ans.append(revc[sarr[index]]);
			else ans.append(sarr[index]);
		}
		ans.append(BA.substring(BA.length()-(n-ans.length())));
		if(index==n && k%2==1)ans.setCharAt(0, 'B');
		out.println(ans.toString());
	}
 
 
 
 
	public static void main(String[] args){ 
		 solve(); 
		 out.flush(); 
	 } 
	 private static InputStream in = System.in; 
	 private static PrintWriter out = new PrintWriter(System.out); 
 
	 private static final byte[] buffer = new byte[1<<15]; 
	 private static int ptr = 0; 
	 private static int buflen = 0; 
	 private static boolean hasNextByte(){ 
		 if(ptr<buflen)return true; 
		 ptr = 0; 
		 try{ 
			 buflen = in.read(buffer); 
		 } catch (IOException e){ 
			 e.printStackTrace(); 
		 } 
		 return buflen>0; 
	 } 
	 private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} 
	 private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} 
	 private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} 
 
	 private static double nd(){ return Double.parseDouble(ns()); } 
	 private static char nc(){ return (char)skip(); } 
	 private static String ns(){ 
		 StringBuilder sb = new StringBuilder(); 
		 for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); 
		 return sb.toString(); 
	 } 
	 private static int[] nia(int n){ 
		 int[] res = new int[n]; 
		 for(int i=0;i<n;++i)res[i]=ni(); 
		 return res; 
	 } 
	 private static long[] nla(int n){ 
		 long[] res = new long[n]; 
		 for(int i=0;i<n;++i)res[i]=nl(); 
		 return res; 
	 } 
	 private static int ni(){ 
		 int res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	 } 
	 private static long nl(){ 
		 long res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	} 
} 



Measured memory_bytes: 28756
import itertools
N=int(input())
slist=[x=="o" for x in input()]
#print(slist)

answer_list=[None]*N

ok=False
for p1,p2 in itertools.product([True,False],repeat=2):
  answer_list[0]=p1
  answer_list[1]=p2
  
  for i in range(2,N):
    if answer_list[i-1]==slist[i-1]:
      answer_list[i]=answer_list[i-2]
    else:
      answer_list[i]=not answer_list[i-2]
        
  contra=False
  for i in range(N):
    l=(i-1)%N
    r=(i+1)%N
    if (answer_list[i]==slist[i])^(answer_list[l]==answer_list[r]):
      contra=True
  if not contra:
    ok=True
    break
    
if ok:
  sw_list=[]
  for ans in answer_list:
    if ans:
      sw_list.append("S")
    else:
      sw_list.append("W")
  print("".join(sw_list))
else:
  print(-1)

Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    


    int a,b,c;
    cin >> a >> b >> c;
 int s = a+b+c;
 if(s>=22)
 cout <<"bust";
 else cout << "win";
    return 0;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll sum1 = 0, sum2 = 0;
    ll ans1 = 0, ans2 = 0;

    rep(i, n){
        if(sum1 + a[i] > 0){
            if(i % 2 == 0) sum1 += a[i];
            else{
                ans1 += 1 + (sum1 + a[i]);
                sum1 = -1;
            }
        }else if(sum1 + a[i] == 0){
            if(i % 2 == 0) sum1 = 1;
            else sum1 = -1;
            ans1++;
        }else{
            if(i % 2 == 0){
                ans1 += 1 + abs(sum1 + a[i]);
                sum1 = 1;
            }else sum1 += a[i];
        }
    }
    rep(i, n){
        if(sum2 + a[i] > 0){
            if(i % 2 == 1) sum2 += a[i];
            else{
                ans2 += 1 + (sum2 + a[i]);
                sum2 = -1;
            }
        }else if(sum2 + a[i] == 0){
            if(i % 2 != 0) sum2 = 1;
            else sum2 = -1;
            ans2++;
        }else{
            if(i % 2 == 1){
                ans2 += 1 + abs(sum2 + a[i]);
                sum2 = 1;
            }else sum2 += a[i];
        }
    }
    cout << min(ans1, ans2) << endl;
}

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

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

    if (a % 3 == 0){
        cout << "Possible" << endl;
        return 0;
    } else if (b % 3 == 0){
        cout << "Possible" << endl;
        return 0;
    } else if ((a+b) % 3 == 0){
        cout << "Possible" << endl;
        return 0;
    }

    cout << "Impossible" << endl;
    return 0;
}

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

string s;

int dfs(string t){
    if(t.size()>s.size() || (t.size() == s.size() && t>s)){
        return 0;
    }
    int res=1;
    for(auto x : {'7', '5', '3'}){
        if(!count(t.begin(), t.end(), x)){
            res = 0;
        }
    }
    return res+dfs(t+"7")+dfs(t+"5")+dfs(t+"3");
}

int main(void){
    cin >> s;
    cout << dfs("") << endl;
    return 0;
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int n ;
	cin>> n ;
	vector<int> p(n), q(n);
	rep(i,n) cin >> p[i] ;
	rep(i,n) cin >> q[i];

	vector<vector<int>> a(0,vector<int> (0));
	vector<int> perm(n);
	rep(i,n){
		perm[i] = i + 1 ;
	}
	int P , Q ;
	int index = 0 ;
	do{
		index ++ ; 
		if(perm == p){
			P = index ;
		}
		if(perm == q){
			Q = index; 
		}
	}while(next_permutation(perm.begin(),perm.end()));
		
		int ans = abs(P - Q);
		cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int K, Q;
ll D[5000];

int main() {
    cin >> K >> Q;
    for (int i = 0; i < K; i++) {
        cin >> D[i];
    }
    
    for (int t = 0; t < Q; t++) {
        int n;
        ll x, m;
        cin >> n >> x >> m;
        x %= m;
        int q = (n - 1) / K, r = (n - 1) % K;
        int cnt = 0;
        for (int i = 0; i < min(K, n - 1); i++) {
            int coef = i < r ? q + 1 : q;
            x += D[i] % m * coef;
            if (D[i] % m == 0)
                cnt += coef;
        }
        cout << n - 1 - x/m - cnt << endl;
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);

  sort(H.rbegin(), H.rend());

  for (int i = 0; i < min(K, N); i++) H.at(i) = 0;

  cout << accumulate(H.begin(), H.end(), 0L) << "\n";
}

Measured memory_bytes: 1024
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a = collections.Counter(a).most_common()
    if len(a) == 1:
        if a[0][0] == 0:
            print("Yes")
        else:
            print("No")
    elif len(a) == 2:
        if a[0][1] == a[1][1] * 2 and a[1][0] == 0:
            print("Yes")
        else:
            print("No")
    elif len(a) == 3:
        if a[0][0] ^ a[1][0] ^ a[2][0] == 0 and a[0][1] == a[1][1] == a[2][1]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


if __name__ == '__main__':
    solve()


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

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

    vector<int> heights(n, 0);
    for(int i=0; i<n; ++i) cin >> heights[i];

    int first = 0;
    int second = abs(heights[1] - heights[0]);
    for(int i=2; i<n; ++i)
    {
        int cur = min(second+abs(heights[i]-heights[i-1]), first+abs(heights[i]-heights[i-2]));
        first = second;
        second = cur;
    }
    
    cout << second << '\n';

    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const int EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, i;
	cin >> N >> i;
	cout << N - i + 1 << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>

#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define ld long double

using namespace std;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
ll ans = 0, mx = 0, mn = 1e9, sum = 0, cnt = 0, avr = 0, index = 0;

//map<int, int>freq;
vector<int>vec;
vector<int>res;
vector<int>freq(10000+5,0);
vector<int>cFreq(150, -1);

int main()
{
	cin >> t >> x;
	double ans = t / (double)x;
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 256
program kadai
    implicit none
    character(len=100001) ::  S
    integer  ::  flag(100001)
    integer  ::  e,l,i,j
    integer  ::  left,med
integer,allocatable  ::  lefflag(:)
    integer  ::  right
    integer,allocatable  ::  ans(:)

    read(*,*) S

    flag=0
    i=1
    e=len_trim(S)
    do i=1,e
        if (S(i:i)=="R") then
            flag(i)=1
        end if
            if (S(i:i)=="L") then
            flag(i)=2
        end if
        if (S(i:i)=="0") then
            e=i
            exit
        end if
    end do

    allocate(ans(e))
    allocate(lefflag(e))

    left=1
    right=0
    lefflag=0
    ans=0
    do i=1,e
        if (flag(i)==2 .and. i>right) then
            if (flag(i+1)==1 .or. i==e) then
                right=i
                l=mod(right-left,2)
                if (l==0) then
                    ans(right)=ans(right)+(right-left+2)/2
                    ans(right-1)=ans(right-1)+(right-left)/2
                end if
                if (l==1) then
                    ans(right)=ans(right)+(right-left+1)/2
                    ans(right-1)=ans(right-1)+(right-left+1)/2
                end if
                left=right+1
            end if
            if (flag(i+1)==2) then
                med=i
                do j=med,e
                    if (j==e) then
                        right=j
                        exit
                    end if
                    if (flag(j)==1) then
                        right=j-1
                        exit
                    end if
                end do
                l=mod(med-left,2)
                if (l==0) then
                    ans(med)=ans(med)+(med-left+2)/2
                    ans(med-1)=ans(med-1)+(med-left)/2
                end if
                if (l==1) then
                    ans(med)=ans(med)+(med-left+1)/2
                    ans(med-1)=ans(med-1)+(med-left+1)/2
                end if

                l=mod(right-med,2)
                if (l==0) then
                    ans(med-1)=ans(med-1)+(right-med)/2
                    ans(med)=ans(med)+(right-med+2)/2-1
                end if
                if (l==1) then
                    ans(med-1)=ans(med-1)+(right-med+1)/2
                    ans(med)=ans(med)+(right-med+1)/2-1
                end if
            end if
        left=right+1
        end if
    end do

write(*,*) ans


stop
contains

end program kadai


Measured memory_bytes: 3364
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s, t;
   cin >> s;
   int q;
   cin >> q;

   rep(i, 0, q) {
      int T;
      cin >> T;
      if (T == 1) {
         swap(t, s);
      } else {
         int f;
         char c;
         cin >> f >> c;
         if (f == 1)
            t += c;
         else
            s += c;
      }
   }
   reverse(t.begin(), t.end());
   t += s;
   cout << t << endl;
   return 0;
}

Measured memory_bytes: 1128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 410

bool peri[N];
vector<int>e[N][N];
vector<int>et[N];
set<int>ett[N];
long long b[N][7];
long long c[60];
bool used[N];
bool en;
int n, m;

void dfs(int s,int x, int k) {
	int y;
	used[x] = true;
	b[s][(x / 60)] += c[(x % 60)];
	f(i, et[x].size()) {
		if (e[x][et[x][i]].size() > 1) {
			if (e[x][et[x][i]][1] < k) {
				y=0;
              peri[s]=true;
				while (y < n) {
					used[y] = true;
					b[s][(y / 60)] += c[(y % 60)];
					y++;
				}
				en = true;
				return;
			}
         }
		if (e[x][et[x][i]][0] < k) {
			if (used[et[x][i]]) {
				y = 0;
              peri[s]=true;
				while (y < n) {
					used[y] = true;
					b[s][(y / 60)] += c[(y % 60)];
					y++;
				}
				en = true;
				return;
			}
			else {
				dfs(s, et[x][i], e[x][et[x][i]][0]);
				if (en)return;
			}
		}
	}
	return;
}


int main() {
	long long z;
	c[0] = 1;
	f(i, 59)c[i + 1] = c[i] * 2;
	f(i, n) {
		f(j, 7)b[i][j] = 0;
	}
	int x, y;
	int ans;
	scanf("%d %d", &n, &m);
	f(i, m) {
		scanf("%d %d", &x, &y);
		e[x - 1][y - 1].push_back(i);
		e[y - 1][x - 1].push_back(i);
		if (ett[x - 1].count(y - 1) == 0) {
			et[x - 1].push_back(y - 1);
			ett[x - 1].insert(y - 1);
		}
		if (ett[y - 1].count(x - 1) == 0) {
			et[y - 1].push_back(x - 1);
			ett[y - 1].insert(x - 1);
		}
	}
	f(i, n) {
		f(j, n)used[j] = false;
		en = false;
      peri[i]=false;
		dfs(i,i, MOD);
	}
	ans = 0;
	f(i, n) {
		f(j, n) {
			if (i < j) {
				z = 0;
				f(ii,7)	z |= (b[i][ii] & b[j][ii]);
				if (z == 0&&!peri[i]&&!peri[j])ans++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
/* Solution by divyanshu0x16*/
#define int           long long 
#define setbits(x)    __builtin_popcountll(x)
#define zerobits(x)   __builtin_ctzll(x)
#define mod           1000000007 
#define modulo(a, b)  (a%b<0 ? a%b+b : a%b)
#define intpow(a,b)   (int)(pow(a,b) + 0.5)
#define gcd(a,b)      __gcd(a, b)
#define all(x)        (x).begin(), (x).end()
#define ps(x, y)      fixed<<setprecision(y)<<x
#define testcase(x)   int x; cin >> x; while(x--)
#define fastIO        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef stack<int> si;
typedef queue<int> qi;
typedef priority_queue<int> pqi;


int32_t main() {
    fastIO;
    int t = 1;
    while(t--){
        int n; cin >> n;
        vi sum;
        vi difference;
        int xi, yi;
        for (int i = 0; i < n; i++)
        {
            cin >> xi >> yi;
            sum.push_back(xi+yi);
            difference.push_back(xi-yi);
        }
        sort(sum.begin(), sum.end());
        sort(difference.begin(), difference.end());
        int ans = max(sum[n-1]-sum[0], difference[n-1]-difference[0]);
        cout << ans << "\n";
    }
    return 0;
}
 

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

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int total = 0;
    for (int i=1; i<=N; i++) {
        int sum = findSumOfDigits(i);
        if (sum >= A && sum <= B) total += i;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,p,q;
  while(cin>>n,n){
    long long a[n]={};a[0]=1;
    for(int i=1;i<=n;i++)
      a[i]=a[i-1]<<1;
    vector<int>v[31];
    for(int i=0;i<n;i++){
      cin>>p;
      for(int j=0;j<p;j++){
        cin>>q;
        v[q].push_back(i);
      }
    }
    for(int i=1;i<31;i++){
      long long l=0;
      for(int j=0;j<v[i].size();j++)
        l=l|a[v[i][j]];
      for(int j=0;j<v[i].size();j++)
        a[v[i][j]]=l;
      if(l==(pow(2,n)-1)){
        cout<<i<<endl;
        break;
      }
      if(i==30)cout<<-1<<endl;
    }
  }
}

Measured memory_bytes: 3220
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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



int main() {
	ll n, k, q;
	cin >> n >> k >> q;
	vector<ll> a(n);
	REP(i, n){
		cin >> a[i];
	}

	ll ans = INF;
	REP(i, n){
		vector<ll> tmp;
		multiset<ll> ms;
		REP(j, n + 1){
			if(j == n || a[j] < a[i]){
				sort(tmp.begin(), tmp.end());
				REP(l, (ll)tmp.size() - k + 1){
					ms.insert(tmp[l]);
				}
				tmp.clear();
			}
			else{
				tmp.push_back(a[j]);
			}
		}
		if(ms.size() < q) continue;
		auto itr = ms.begin();
		REP(j, q - 1) itr++;
		ans = min(ans, *itr - a[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<ll> H(n+1); rep(i,n+1) cin>>H.at(i);
  vector<ll> A(n+1); rep(i,n) cin>>A.at(i);
  ll ans=0;
  ll restA=0,restH=0;
  rep(i,n){
    ans+=min(H.at(i),restA);
    restH=max(0LL,H.at(i)-restA);
    ans+=min(A.at(i),restH);
    restA=max(0LL,A.at(i)-restH);
  }
  ans+=min(restA,H.at(n));
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static final Scanner sc    = new Scanner(System.in);
    static final int     MOD   = (int) 1E9 + 7;
    static final long    INF_L = (long) 4E18;
    static final int     INF   = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        int N = nint();
        String[] s = new String[N];
        int[] t = new int[N];
        for (int i = 0; i < N; i++) {
            s[i] = nstr();
            t[i] = nint();
        }
        String X = nstr();
        
        int in = IntStream.range(0, N).filter(i -> s[i].equals(X)).findFirst().getAsInt();
        int ans = 0;
        for (int i = in + 1; i < N; i++) {
            ans+= t[i];
        }
        System.out.println(ans);
    }
    
    @Deprecated
    static int nint() {
        return sc.nextInt();
    }

    @Deprecated
    static int[] nints(int N) {
        return nints(N, 0, 0);
    }

    @Deprecated
    private static int[] nints(int N, int padL, int padR) {
        int[] a = new int[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nint();
        return a;
    }

    static long nlong() {
        return sc.nextLong();
    }

    static long[] nlongs(int N) {
        return nlongs(N, 0, 0);
    }

    static long[] nlongs(int N, int padL, int padR) {
        long[] a = new long[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nlong();
        return a;
    }

    static double ndouble() {
        return sc.nextDouble();
    }

    static double[] ndoubles(int N) {
        return ndoubles(N, 0, 0);
    }

    static double[] ndoubles(int N, int padL, int padR) {
        double[] d = new double[N + padL + padR];
        for (int i = 0; i < N; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    static String nstr() {
        return sc.next();
    }

    static char[] nchars() {
        return sc.next().toCharArray();
    }

    static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    static char[][] nchars2(int H, int W) {
        return nchars2(H, W, 0, 0);
    }

    static char[][] nchars2(int H, int W, int padLU, int padRD) {
        char[][] a2 = new char[H + padLU + padRD][W + padLU + padRD];
        for (int i = 0; i < H; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, W);
        return a2;
    }

    static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }

    static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }

    static long abs(long a) {
        return Math.abs(a);
    }
}


Measured memory_bytes: 26708