akhauriyash/Code-Regression huggingface dataset:
s = gets.to_i

if s < 3
  puts 0
else
  size = s / 3
  answer = 1
  (2..size).each do |n|
    rest = s - (3 * n)
    if rest.zero?
      answer += 1
    else
      if rest == 1
        answer += n
      else
        a = n + rest - 1
        b = rest
        answer += (a - b + 1..a).inject(1, :*) / (1..b).inject(1, :*)
      end
    end
  end

  puts answer % (10 ** 9 + 7)
end


Measured memory_bytes: 18324
#include <cstdio>
long long gcd(int x, int y) {
	if (!x) return y;
	if (!y) return x;
	return gcd(y, x%y);
}
int main() {
	long long a, b, c, d;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d); a--;
	long long l = c*d/gcd(c,d);
	long long ans = b-a+a/c-b/c+a/d-b/d-a/l+b/l;
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.next();
    let mut a = sc.vec::<u32>(n);

    for i in 0..n {
        let v = a[i];
        let mut j = 0;

        while a[j] < v {
            j += 1;
        }

        for k in (j..i).rev() {
            a[k + 1] = a[k];
        }
        a[j] = v;

        for (i, x) in a.iter().enumerate() {
            print!("{}{}", x, if i == n - 1 { '\n' } else { ' ' });
        }
    }
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}



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

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

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

using namespace std;

int main(){
    int A,B,C;
    int ans;
    cin >> A >> B >> C;
    ans = A + B;
    if(A < B){
        if(B < C){
            ans = 10*C + A + B; 
        }else{
            ans = 10*B + A + C; 
        }
    }else{
        if(A < C){
            ans = 10*C + A + B; 
        }else{
            ans = 10*A + B + C; 
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
n = int(input())
#n,m = map(int,input().split())
#lst1 = list(map(int,input().split()))
dic1 = dict()
for i in range(n):
    s = input()
    if s in dic1:
        dic1[s] += 1
    else:
        dic1[s] = 1

ma = max(dic1.values())
lst1 = []
for i in dic1:
    if dic1[i] == ma:
        lst1.append(i)

lst1.sort()
for i in lst1:
    print(i)



Measured memory_bytes: 91992
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K, Q;
  cin >> N >> K >> Q;
  vector<ll> A(Q);
  vector<ll> times(N,0);
  REP(i,Q){
    cin >> A[i];
    A[i]--;
    times[A[i]]++;
  }
  if(K<=Q){
    REP(i,N){
      if(K-Q+times[i]>0) cout << "Yes" << endl;
      else cout << "No" << endl;  
    }
  }else{
    REP(i,N){
      cout << "Yes" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2176
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<map> 
#include<string>
#include<queue>
#include<stack> 
#include<bitset>
#include<list>
#include<set>
#include<utility>
#define IO ios::sync_with_stdio(false)
//#define int long long
using namespace std;
int n;
int main()
{
	cin>>n;
	if(n%1000==0)
	{
		cout<<"0";
	}
	else
	cout<<1000-n%1000;
}

Measured memory_bytes: 3604
n, x, y = map(int, input().split())
ans = [0 for i in range(n-1)]
for i in range(n-1):
  k = i + 1
  b_1 = k - x
  for j in range(i+1, n):
    l = j + 1
    a = l - k
    b = abs(k - x) + abs(l - y) + 1
    if b < a:
      ans[b-1] += 1
    else:
      ans[a-1] += 1
for i in range(n-1):
  print(ans[i])

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

int main() {
    int n; cin >> n;
    stack<int> s;
    if(n == 0) s.emplace(0);
    while(n != 0) {
        int r = n % -2;
        n /= -2;
        if(r < 0) {
            r += 2;
            n++;
        }
        s.emplace(r); 
    }
    while(!s.empty()) printf("%d", s.top()), s.pop();
}

Measured memory_bytes: 256
var 
  a,b:longint;
  s1,s:string;
begin
  read(a,b);
  str(a,s1);
  str(b,s);
  s:=s1+s;
  val(s,a);
  if trunc(sqrt(a))=sqrt(a) then writeln('Yes') 
                            else writeln('No');
end.

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

int main() {

int x, y;
cin >> x >> y;
if(y%2==1){
    cout << "No" << endl;
}
else if(y>=2*x&&y<=4*x){
    cout << "Yes" << endl;
}
else{
    cout << "No" << endl;
}
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;

int main(){
    int x,n;
    cin>>x>>n;
    vector<int>p(100);
    vector<int>q(101);
    for(int i=0;i<n;i++){
        cin>>p[i];
        q[p[i]]++;
    }
    for(int i=0;i<1000;i++){
        if(q[x-i]==0){
            cout<<x-i<<endl;
            break;
        }
        if(q[x+i]==0){
            cout<<x+i<<endl;
            break;
        }
    }
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){

int n;
long long a=0;
cin >>n;

vector<int> vec(n);

for(int i=0;i<n;i++){
cin>>vec.at(i);
}

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

for(int i=0;i<n;i++){
a+=vec.at(i);
}

cout <<vec.at(0)<<" "<<vec.at(n-1)<<" "<<a<<endl;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    int ans = 0;
    int tmp = 0;

    rep(i,n){
        if(tmp >= h[i]) tmp = h[i];
        else{
            ans += h[i] - tmp;
            tmp = h[i];
        }
    }

    dunk(ans);
}



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

using namespace std;

char s[100002];
int n;

bool check() {
    for(int i = 2; i<n; i+=2)
        if( s[i] != s[0] ) return false;
    for(int i = n-3; i>=0; i-=2)
        if( s[i] != s[n-1] ) return false;
    return true;
}

int main() {
    scanf("%s", s);
    n = strlen(s);
    if( check() ) {
        puts("Second");
        return 0;
    }
    if( s[0] == s[n-1] ) puts( ((n-3)&1) ? "First" : "Second" );
    else puts( ((n-2)&1) ? "First" : "Second" );
}



Measured memory_bytes: 512
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vector<pair<ll, ll>> vec(n);
    REP(i, n) {
        ll x, y;
        cin >> x >> y;
        vec[i] = make_pair(x, y);
    }
    vector<ll> order(n);
    REP(i, n) {
        order[i] = i;
    }

    vector<double> dists;
    do {
        double dist = 0;
        REP(i, n-1) {
            ll x1 = vec.at(order[i]).first, y1 = vec.at(order[i]).second;
            ll x2 = vec.at(order[i+1]).first, y2 =  vec.at(order[i+1]).second;
            double d = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
            dist += d;
        }
        dists.push_back(dist);
    } while (next_permutation(ALL(order)));

    double num = accumulate(ALL(dists), 0.0) / dists.size();
    printf("%.10f\n", num);
    return 0;
}

Measured memory_bytes: 892
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define sc(x) scanf("%lld",&x)
    #define pf(x) printf("%lld\n",x)
    #define int long long
    #define all(x) x.begin(),x.end() 
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int INF = 1e15;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ DEB $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;


    vector<string> vec_splitter(string s) 
    {
        for(char& c: s) c = c == ','?  ' ': c;
        stringstream ss; ss << s;
        vector<string> res;
        for(string z; ss >> z; res.push_back(z));
        return res;
    }
    void debug_out(vector<string> args, int idx) { cerr << endl; }
    template <typename Head, typename... Tail>
    void debug_out(vector<string> args, int idx, Head H, Tail... T) 
    {
        if(idx > 0) cerr << ", ";
        stringstream ss; ss << H;
        cerr << args[idx] << " = " << ss.str();
        debug_out(args, idx + 1, T...);
    }
    
    #ifdef XOX
    #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
    #else
    #define debug(...) 42
    #endif

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    int A[MAX],B[MAX],cnt,c;
    string s;

    void solve()
    {
        cin>>n>>k>>c>>s;
        cnt=1;
        i=0;
        while(cnt<=k && i<n)
        {
            if(s[i]=='o')
            {
                A[i]=cnt++;
                i+=c;
            }
            i++;
        }

        cnt=k;
        i=n-1;
        while(cnt>=0 && i>=0)
        {
            if(s[i]=='o')
            {
                B[i]=cnt--;
                i-=c;

            }
            i--;
        }

        fo(i,0,n)if(A[i]!=0 && A[i]==B[i])cout<<i+1<<endl;
        
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);

        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 7444
using System;
using System.Collections.Generic;

namespace algorithm
{
	class Program
	{
		static void Main(string[] args)
		{
			Dictionary<string, string> t =
			new Dictionary<string, string>();

			t.Add("A", "T");
			t.Add("T", "A");
			t.Add("C", "G");
			t.Add("G", "C");
			Console.WriteLine(t[Console.ReadLine()]);
		}

	}
}


Measured memory_bytes: 11104
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		double a;
		int n;

		while (sc.hasNext()) {
			a = sc.nextDouble();

			n = 1;
			while (true) {
				if (a <= Math.sqrt(9.8 * 9.8 * (5 * n - 5) / 4.9)) {
					System.out.println(n);
					break;
				}
				n++;
			}
		}
	}
}

Measured memory_bytes: 12000
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();
        int N = scanner.nextInt();
        ArrayList<Integer> A = new ArrayList<>();

        for(int i=0; i<N; i++){
            A.add(scanner.nextInt());
        }
        int maxbet = 0;
        for(int i=0; i<N-1; i++){
            int bet = A.get(i+1) - A.get(i);
            if(bet > maxbet){
                maxbet = bet;
            }
        }
        int bet0andN = A.get(0) + (K-A.get(N-1));
        if(maxbet < bet0andN){
            maxbet = bet0andN;
        }
        System.out.println(K - maxbet);
    }
}

Measured memory_bytes: 81676
#include <iostream>
#include <assert.h>

int main() {
    int H, W, h, w = 0;
    std::cin >> H >> W;
    std::cin >> h >> w;
    assert((H >= 0) && (W >= 0) && (h >= 0) && (w >= 0));
    std::cout << H*W - (H*w + h*W - h*w) << '\n';
    return (0);
}

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

int main() {
	int N, K, Q, A;
	cin >> N >> K >> Q;
	vector<int> a(1 + N);
	for (int i = 0; i < Q; ++i) {
		cin >> A;
		++a.front();
		++a[A];
		--a[A - 1];
		--a.back();
	}
	for (int i = 1; i < 1 + N; ++i) a[i] += a[i - 1];
	for (int i = 0; i < N; ++i) {
		if (0 < K - a[i]) cout << "Yes";
		else cout << "No";
		cout << endl;
	}
}

Measured memory_bytes: 1024
#include <cstdio>
#include <string.h>

using namespace std;

namespace {

const size_t kHashSize = 244140624;

class Dictionary {
 public:
  Dictionary() : table_(new int[kHashSize]) {}
  ~Dictionary() { /* delete[] table_; */ }

  void insert(const char* k, size_t n) {
    const size_t i = Encode(k, n);
    table_[i] = 1;
  }

  bool find(const char* k, size_t n) const {
    return table_[Encode(k, n)] > 0;
  }

 private:
  static int Id(char c) {
      switch (c) {
        case 'A':
          return 1;
        case 'C':
          return 2;
        case 'G':
          return 3;
        case 'T':
          return 4;
      }
      // should not reach here.
      return 0;
  }

  size_t Encode(const char* k, size_t n) const {
    size_t h = 0;
    size_t p = 1;
    for (size_t i = 0; i < n; ++i) {
      h += p * Id(k[i]);
      p *= 5;
    }
    return h;
  }

  int* table_;
};

} // namespace

int main() {
  int n;
  scanf("%d", &n);

  Dictionary d;
  char op[7];
  char str[13];
  for (int i = 0; i < n; ++i) {
    scanf("%s ", op);
    scanf("%s", str);
    const char c = op[0];
    const size_t len = strnlen(str, 13);
    if (c == 'i') {
      d.insert(str, len);
      continue;
    }

    if (d.find(str, len)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}

Measured memory_bytes: 40236
#include <stdio.h>

int main(void) 
{

	char ch[2000] = { 0 };
	char W[15] = { 0 };
	int i, j, k, l, m, n, o, p;

	m = 0;
	while (1) {

		scanf("%c", &W[m]);
		if (W[m] == '\n') {
			break;
		}
		m = m + 1;
	}

	n = 0;
	while (1) {

		scanf("%c", &ch[n]);

		if (ch[n] == 'T' && ch[n - 1] == 'X' && ch[n - 2] == 'E' && ch[n - 3] == 'T' && ch[n - 4] == '_' && ch[n - 5] == 'F' && ch[n - 6] == 'O' && ch[n - 7] == '_' && ch[n - 8] == 'D' && ch[n - 9] == 'N' && ch[n - 10] == 'E') {

			break;
		}
		n += 1;
	}



	p = 0;
	for (i = 0; i < n; i++){
		if (W[0] == ch[i] || W[0] == ch[i] + 32 || W[0] == ch[i] - 32) {
			if (ch[i + m] == ' ' || ch[i + m] == '\n' || W[0] == ch[0]) {
				if (ch[i - 1] == ' ' || ch[i - 1] == '\n' || W[0] == ch[0] + 32 || W[0] == ch[0] - 32){
					o = o + 1;

					for (j = 0; j < m; j++) {
						if (W[j] == ch[i + j] || W[j] == ch[i + j] + 32 || W[j] == ch[i + j] - 32){
							o = o + 1;
						}
					}
				}
			}

			if (o == m + 1){
				p = p + 1;
			}
			o = 0;
		}
	}

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

	return 0;

}


Measured memory_bytes: 2112
N, M , Q = map(int, input().split())

LR = [[0 for _ in range(N+2-i)] for i in range(N+2)]
for i in range(M):
  L, R = map(int, input().split())
  LR[L][R-L+1] += 1

  
for i in range(2,N+2):
  for j in range(1,N-i+2):
    LR[j][i] += LR[j][i-1] + LR[j+1][i-1] - LR[j+1][i-2]
 
A = []
for i in range(Q):
  p, q = map(int, input().split())
  A.append(LR[p][q-p+1]-LR[q+1][0])

print("\n".join(map(str,A)))


Measured memory_bytes: 18856
//11
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(long long h,w,l;cin>>h>>w>>l,h|w|l;){
    bool s[102][102]={};
    int x,y,d;
    string ds="NESW";
    for(int i=1;i<=h;i++){
      for(int j=1;j<=w;j++){
	char c;
	cin>>c;
	s[i][j]=c!='#';
	if(c!='#'&&c!='.'){
	  x=j;
	  y=i;
	  d=ds.find(c);
	}
      }
    }
    long long p[102][102][4];
    fill(p[0][0],p[102][0],-1);
    while(l){
      int dx[]={0,1,0,-1};
      int dy[]={-1,0,1,0};
      for(;;){
	if(s[y+dy[d]][x+dx[d]])break;
	d=(d+1)%4;
      }
      y+=dy[d];
      x+=dx[d];
      l--;
      if(p[y][x][d]!=-1){
	l%=p[y][x][d]-l;
      }
      p[y][x][d]=l;
    }
    cout<<y<<' '<<x<<' '<<ds[d]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1548
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define prev asnjsd
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define Aint(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FIint(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

const int mod = 1000 * 1000 * 1000 + 7;
const int MAX = 1107;
vector<int> ans;
int n , a , b;
vector<int> go(int a , int b , int maska , int idx)
{
	vector<int> Ans;
	if(idx == n - 1)
	{
		Ans.PB(a);
		Ans.PB(b);
		return Ans;
	}
	int bit = 0;
	for(int i = 0; i < n; i++)
	{
		if((a & (1 << i)) != (b & (1 << i)))
		{
			bit = i;
		}
	}
	int kydu = a;
	for(int i = 0; i < n; i++)
	{
		if(!(maska & (1 << i)) && i != bit)
		{
			kydu = a ^ (1 << i);
		}
	}
	vector<int> res = go(a , kydu , maska | (1 << bit) , idx + 1);
	vector<int> res2 = go(kydu ^ (1 << bit) , b , maska | (1 << bit) , idx + 1);
	for(auto v : res2)
		res.PB(v);
	return res;
}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
	cin >> n >> a >> b;
	int c = a ^ b;
	if(__builtin_popcount(c) % 2 == 0)
	{
		cout << "NO";
		return 0;
	}
	ans = go(0 , c, 0 , 0);
	cout << "YES" << endl;
	for(auto x : ans)
	{
		cout << (x ^ a) << " ";
	}
    return 0;
}


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

vector<pair<int,int> > p;
bool cmp(pair<int,int> p1,pair<int,int> p2){
    return min(p1.second,p1.first+p2.second)>min(p2.second,p2.first+p1.second);
}
int main(){
    int n,sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        string s;
        int cnt=0,mn=0;
        cin>>s;
        for(int j=0;j<s.length();j++){
            char c=s[j];
            if(c=='(') cnt++;
            else cnt--;
            mn=min(mn,cnt);
        }
        p.push_back({cnt,mn});
        sum+=cnt;
    }
    if(sum!=0) {
        printf("No");
        return 0;
    }
    sort(p.begin(),p.end(),cmp);
    int res=0;
    for(int i=0;i<p.size();i++){
        if(res< -p[i].second){
            printf("No");
            return 0;
        }
        res+=p[i].first;
    }
    printf("Yes");
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll a,b,c;
string s;
map<char, ll> m;
ll mx = 0;
int main(){
	cin >> s;
	REP(i,0,4){
		m[s[i]]++;
		mx = max(mx, m[s[i]]);
	}

	if(mx == 2 && m.size()==2){
		p("Yes");
	}else{
		p("No");
	}
	return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n,x,i,a,b;
	t = 1;
	while(t--) {
	 a = 1, b = 0;
	 cin >> n >> x;
	 int arr[n];
	 for(i = 0; i < n; i++)
	  cin >> arr[i];
	 for(i = 0; i < n; i++) {
	  b = b + arr[i];
 	 if(b > x)
 	  break;
 	 a++;
 	}
	 cout << a << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
// ----- boost -----
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
// ----- using directives and manipulations -----
using boost::rational;
using boost::multiprecision::cpp_int;
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

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>;
 
int64_t N, K, A[200000], F[200000];
 
bool check(int64_t X){
    int64_t need = 0;
    for(int i=0; i<N; i++){
        int64_t ok = X/F[i];
        if(ok < A[i]) need += A[i] - ok;
    }
    return (need <= K);
}
 
int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> F[i];
    sort(A, A+N);
    sort(F, F+N, greater<>());
    int64_t ok = 1e13, ng = -1;
    while(ok-ng>1){
        int64_t mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        Integer A[]= new Integer[N];
        int sum = 0;
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            sum += A[i];
        }
        Arrays.sort(A,Collections.reverseOrder());
        int b = A[M-1]*4*M;
        if(b<sum){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }

    }
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(),v.end()
#define sz(x) (int)sz.size()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;

#ifdef LOCAL//ONLINE_JUDGE
#include "D:\c_c++\template.h"
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    //assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}

void solve(){
	ll x;
	cin>>x;
	debug("hahah");
	cout<<(!x)<<'\n';
	debug("bhai bhai");
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
//    #ifdef LOCAL
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
    int tc=1;
    // cin>>tc;
    while(tc--)solve();
}


Measured memory_bytes: 3644
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] T = new int[N];
    int sum = 0;
    for(int i=0;i<N;i++){
      T[i] = sc.nextInt();
      sum += T[i];
    }
    int M = sc.nextInt();
    for(int i=0;i<M;i++){
      int P = sc.nextInt();
      int X = sc.nextInt();
      int ans = sum-T[P-1]+X;
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 36336
Module Program
  Sub Main
    Dim s=Gets()
    Dim a=s(0),b=s(1)
    Dim ans=If(a<b,"<",If(a>b,">","="))
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22352
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector< string > S(H);
	rep(i, H) cin >> S[i];
	int k = 0;
	vector< vector< int > > ans(H, vector< int >(W, 0));
	rep(i, H) {

		bool f = false;
		rep(j, W) if (S[i][j] == '#') f = true;
		if (!f)
			continue;
		++k;
		f = false;
		rep(j, W) {
			if (S[i][j] == '.') {
				ans[i][j] = k;
			} else {
				if (f)
					ans[i][j] = ++k;
				else
					ans[i][j] = k;
				f = true;
			}
		}
	}
	rep(i, H) {
		if (ans[i][0] != 0)
			continue;
		if (i == 0) {
			int k = 1;
			while (ans[k][0] == 0)
				k++;
			rep(j, W) ans[i][j] = ans[k][j];
		} else {
			rep(j, W) {
				ans[i][j] = ans[i - 1][j];
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n;
    cin>>n;
    long long int ans=INT_MAX,curr=0;
    long long int a[n];
    for(auto &x:a)cin>>x;
    for(auto x:a)
    {
        curr=0;
        while(x%2==0)
        {
            x/=2;
            curr++;
        }
        ans=min(ans,curr);
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
    long long H,W;
    cin >> H >> W;
    
    if(W == 0 or H == 0){
        cout << 0;
        return 0;
    }
    
    if(W == 1){
        cout << 1;
        return 0;
    }
    
    if(H == 1){
        cout << 1;
        return 0;
    }
    
    long long ans = int((W / 2.0) + 0.5) * H;
    
    if(W % 2 != 0){
        ans = ans - (H / 2);
    }
    
    cout << ans;
}


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

signed main(){

  int q;
  cin>>q;
  set<int> s;
  while(q--){
    int c,x;
    cin>>c>>x;
    if(c==0){
      s.insert(x);
      cout<< s.size() <<endl;
    }
    else if(c==1){
      cout<< s.count(x) <<endl;
    }
    else if(c==2){
      s.erase(x);
    }
  }

}


Measured memory_bytes: 12460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int x; sc(x)
    int ans = 1, tmp;
    for (int i = 2; i < x; i++){
        tmp = i*i;
        while (x >= tmp){
            ans = max(ans, tmp);
            tmp *= i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int n,m,q,a,b,c,d,rui[1005][1005][3],ret[3];char f[1005][1005],e[3]={'J','O','I'};
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=0;i<n;i++) scanf("%s",&f[i]);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) for(int k=0;k<3;k++)
    rui[i][j][k]=rui[i-1][j][k]+rui[i][j-1][k]-rui[i-1][j-1][k]+(f[i-1][j-1]==e[k]);
    for(int i=0;i<q;i++){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        for(int j=0;j<3;j++) ret[j]=rui[c][d][j]-rui[c][b-1][j]-rui[a-1][d][j]+rui[a-1][b-1][j];
        printf("%d %d %d\n",ret[0],ret[1],ret[2]);
    }
}

Measured memory_bytes: 13672
// D - Triangles
// 累積和による方法
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

ll solve(int N, vi &L){
	vl csum(2000+1); //[length]<count>: 累積和: cumulative sum
	rp(i, 0, N) csum[L[i]]++;
	rp(i, 1, csum.size()) csum[i] += csum[i-1]; // その長さまでの棒の個数
	ll ans = 0;
	rp(ia, 0, N-1){
		rp(ib, ia+1, N){
			int a = L[ia], b = L[ib];
			int minL = abs(a - b), maxL = a + b; // |a-b| < c < a+b : cの範囲
			ans += csum[maxL-1] - csum[minL]; // maxL-1 に注意！cの範囲に(等号はない)
			if(minL<a && a<maxL) ans--; // cの範囲にaがあれば一本不要
			if(minL<b && b<maxL) ans--; // cの範囲にbがあれば一本不要
		}
	}
	return ans/3; //3本で△1つ
}

int main(){
	int N; cin>>N;
	vi L(N); rp(i, 0, N) cin>>L[i];
	cout<< solve(N, L) <<endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def lcm(a,b): return a*b//fractions.gcd(a,b)

def main():
  n=I()
  l=LI()

  a=1
  for x in l:
    a=lcm(a,x)

  ans=0
  for x in l:
    ans+=a//x

  return ans%mod

# main()
print(main())


Measured memory_bytes: 6488
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		double W = stdIn.nextDouble();
		double H = stdIn.nextDouble();
		double x = stdIn.nextDouble();
		double y = stdIn.nextDouble();
		
		System.out.println(W*H/2);
		
		if(x == W/2 && y == H/2) {
			System.out.println(1);
		}
		else {
			System.out.println(0);
		}

	}

}

Measured memory_bytes: 25172
#include <stdio.h>

int main(void) {
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	if(a<=b && a<=c){
		if(b<=c){
			printf("%d %d %d\n",a ,b ,c);
		}else{
			printf("%d %d %d\n",a ,c ,b);
		}
	}else if(b<=a && b<=c){
		if(a<=c){
			printf("%d %d %d\n",b ,a ,c);
		}else{
			printf("%d %d %d\n",b ,c ,a);
		}
	}else if(c<=a && c<=b){
		if(a<=b){
			printf("%d %d %d\n",c ,a ,b);
		}else{
			printf("%d %d %d\n",c ,b ,a);
		}
	}
	return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int X, Y;
	cin >> X >> Y;

	int ans = 0;
	if (X == 1) {
		ans += 3;
	}
	if (X == 2) {
		ans += 2;
	}
	if (X == 3) {
		ans += 1;
	}
	if (Y == 1) {
		ans += 3;
	}
	if (Y == 2) {
		ans += 2;
	}
	if (Y == 3) {
		ans += 1;
	}
	if (X == 1 && Y == 1) {
		ans += 4;
	}
	cout << ans * 100000 << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    int max = (a > b) ? a : b;
    int min = (a > b) ? b : a;
    while (max % min)
    {
        int tmp = max % min;
        max = min;
        min = tmp;
    }
    return min;
}
int main()
{
    int n, x, ans(0);
    cin >> n >> x;
    int city[n];
    for (int &i : city)
    {
        cin >> i;
        i -= x;
    }
    if (n > 1)
    {
        ans = gcd(abs(city[0]), abs(city[1]));
        for (int i = 2; i < n; ++i)
        {
            ans = gcd(abs(ans), abs(city[i]));
        }
    }
    else if (n == 1)
        ans = abs(city[0]);
    cout << ans << endl;
}

Measured memory_bytes: 640
N=int(input())
s=list(map(int,input().split()))

ans=0
for a in range(1,N):
    Sf=0
    Sb=0
    used=[False]*((N-1)//a+1)
    for j in range((N-2)//a):
        Sf+=s[a*j]
        Sb+=s[N-1-a*j]
        if used[j]:
            break
        else:
            used[j]=True
        if (N-1-a*j)%a==0:
            if used[(N-1-a*j)//a]:
                break
            else:
                used[(N-1-a*j)//a]=True
        temp=Sf+Sb
        ans=max(ans,temp)

print(ans)


Measured memory_bytes: 86816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i <= (n); ++i)
#define repD(i, a, n) for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define mem(a) memset(a, 0, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
ll mod = 1000000007;
int Ceil(int a, int b){
	if(a%b==0) return a/b;
	else return (a/b)+1;
}

int main() {
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);   
	// freopen("output.txt", "w", stdout);
	// #endif
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	ll a,b,x,ans=0;
	cin >> a >> b >> x;
	if(a==0){
		ans++;
		ans+=b/x;
		cout << ans << "\n";
	}
	else {
		ans+=b/x;
		ans-=(a-1)/x;
		cout << ans << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

ll gcd(ll a, ll b) {
    //cout << "gcd " << a << " " << b << endl;
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    //cout << "lcm " << a << " " << b << endl;
    return a / gcd(max(a, b), min(a, b)) * b; //先に割る!!
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll ans = 1;
    rep(i, n) {
        ll t; cin >> t;
        ans = lcm(ans, t);
        //cout << ans << endl;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
if __name__ == '__main__':
    n = input()
    s = {}
    for i in range(n):
        a = raw_input()
        if a not in s.keys():
            s[a] = 1
        else:
            s[a] += 1
    m = input()
    t = {}
    for i in range(m):
        a = raw_input()
        if a not in t.keys():
            t[a] = 1
        else:
            t[a] += 1
    m = 0
    for a in s.keys():
        if a in t.keys():
            m = max(m, s[a] - t[a])
        else:
            m = max(m, s[a])
    print m


Measured memory_bytes: 2692
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
signed main() {
	int n;
	cin >> n;
	cout << n * (n - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits>
#include <cfenv>
#include <cmath>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <list>
#include <random>
#include <functional>


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

using lli = long long int;
using pii = std::pair<int, int>;

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


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


template <int N, int mod>
struct Init{
    long long int Power[N+1], powInverse[N+1], powInvS[N + 1], Inverse[N + 1];
    constexpr Init():Power(), powInverse(), powInvS(), Inverse(){
        Power[0] = 1; powInverse[0] = 1, powInvS[0] = 0; Inverse[0] = 1;
        for(int x = 1; x <= N; ++x) Power[x] = (Power[x-1] * x) % mod;
        powInverse[N] = inverse(Power[N]);
        for(int x = N; x > 0; --x){
            Inverse[x] = powInverse[x] * Power[x-1] % mod;
            powInverse[x-1] = (powInverse[x] * x) % mod;
        }
        for(int x = 1; x <= N; ++x){
                powInvS[x] = powInvS[x-1] + Inverse[x];
                if(powInvS[x] >= mod) powInvS[x] -= mod;
        }
    }
    constexpr void swap(lli &a, lli &b) const {
        a ^= b; b ^= a; a ^= b;
    }
    constexpr long long int inverse(long long int a) const noexcept{
        long long int b = mod, u = 1, v = 0;
        while (b != 0) { 
            long long int t = a / b; a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= mod; if (u < 0) u += mod;
        return u;
    }
    inline long long int query(int q1, int q2) const noexcept{
        return powInvS[q1] + powInvS[q2];
    }
};

constexpr int N = 1e5;
constexpr int mod = 1e9 + 7;
constexpr Init<N, mod> Q;

int main(void){
    int n; scanf("%d", &n);
    lli res = 0;
    REP(i, n){
        int a; scanf("%d", &a);
        lli val = Q.query(i + 1, n - i) - 1; if(val < 0) val += mod;
        (res += val * a) %= mod;
    }
    (res *= Q.Power[n]) %= mod;
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()
	q := scanInt()
	
	bits := make([]bit,n)
	for i := 0; i < n; i++ {
		bits[i] = make(bit, n+1)
	}

	for i := 0; i < m; i++ {
		l := scanInt()-1
		r := scanInt()-1
		for j := 0; j < l+1; j++ {
			bits[j].add(r,1)
		}
	}

	for i := 0; i < q; i++ {
		p := scanInt()-1
		q := scanInt()-1

		fmt.Fprintln(wr, bits[p].sum(q))
	}
	wr.Flush()
}

type bit []int

func (t bit) sum(i int) int {
	s := 0
	for i++; i > 0; i -= i & -i { s += t[i] }
	return s
}

func (t bit) add(i, x int) {
	for i++; i < len(t); i += i & -i { t[i] += x }
}



Measured memory_bytes: 6016
f_h,h,f_t,total = map(int,[input() for _ in range(4)])
ans = 0
for i in range(f_h+1):
    for j in range(h+1):
        for k in range(f_t+1):
            if 500*i + 100*j + 50*k == total:
                ans += 1
        
        
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
#define MAX 100000

int partition(int a[],int n,int p,int r){
  int x,i,j,t;

  x = a[r];
  i = p - 1;

  for(j = p;j < r;j++){
    if(a[j] <= x){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }

  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;

  return i + 1;
}

int main(){
  int a[MAX],n,i,q;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }

  q = partition(a,n,0,n - 1);

  for(i = 0;i < n;i++){
    if(i > 0) printf(" ");
    if(i == q) printf("[");
    printf("%d",a[i]);
    if(i == q) printf("]");
  }

  printf("\n");
  
  return 0;
}



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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int n;
  cin>>n;
  set<ll> s;
  auto in = []()->ll{
    ll x;cin>>x;return x;
  };
  rep(i,n){
    s.emplace(in());
  }

  cout<<(s.size())<<endl;

}


Measured memory_bytes: 7772
#include<iostream>
#include<algorithm>
using namespace std;
main(){
  int n;
  while( cin >> n && n ){
    int sum, x, maxv = 0, minv = (1<<20);
    for ( int i = 0; i < n; i++ ){
      sum = 0;
      for ( int j = 0; j < 5; j++ ){
	cin >> x; sum += x;
      }
      maxv = max(maxv, sum);
      minv = min(minv, sum);
    }
    cout << maxv << " " << minv << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[102][5][5][5];

int main(void){
    ll n;
    cin>>n;
    dp[0][0][0][0]=1;
    for(ll x=0;x<n;x++){
        for(ll h=0;h<5;h++){
            for(ll i=0;i<5;i++){
                for(ll j=0;j<5;j++){
                    for(ll k=1;k<5;k++){
                        if (h == 1 && i == 2 && k == 3) continue;
                        if (h == 1 && j == 2 && k == 3) continue;
                        if (i == 1 && j == 2 && k == 3) continue;
                        if (i == 2 && j == 1 && k == 3) continue;
                        if (i == 1 && j == 3 && k == 2) continue;
                        dp[x+1][i][j][k]=(dp[x+1][i][j][k]+dp[x][h][i][j])%N;
                    }
                }
            }
        }
    }
    ll ans=0;
    for(ll i=1;i<5;i++){
        for(ll j=1;j<5;j++){
            for(ll k=1;k<5;k++){
                ans=(ans+dp[n][i][j][k])%N;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main()
{
	int n, k;
	int x[100];
	int ans = 0;
	
	cin >> n >> k;
	
	for (int i = 0; i < n; i++) cin >> x[i];
	
	for (int i = 0; i < n; i++) {
		ans += min(x[i], abs(x[i] - k));
	}
	
	cout << ans * 2 << endl;
	
	return (0);
}

Measured memory_bytes: 256