akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int k,a,b;
  	cin >> k >> a >> b;
  	
  	if (a % k == 0 || b % k == 0) cout << "OK" << endl;
  	else if ((a / k + 1) * k > b) cout << "NG" << endl;
  	else cout << "OK" << endl;
}

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

#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fast_io;

    string n;
    cin >> n;
    ll temp = 0;
    ll sum = 0;
    for(int i =0 ; i< n.size(); i++)
    {
        temp =( n[i] - '0');
        sum += temp ;
    }
    if(sum % 9 == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


Measured memory_bytes: 3756
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main() {
    int arr[5];
    for(int i = 0; i < 5; ++i) cin >> arr[i];
    sort(arr, arr+5);
    for(int i = 4; i > 0; --i)   cout << arr[i] << " ";
    cout << arr[0] <<endl;
    return 0;
}



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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    vector<pair<LD,string>> v(n);
    string l;
    LD p,a,b,c,d,e,f,s,m;
    for(int i=0;i<n;i++){
      cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      v[i]={-(f*s*m-p)/(a+b+c+(d+e)*m),l};
    }
    sort(all(v));
    for(int i=0;i<n;i++){
      cout << v[i].second << endl;
    }
    cout << "#" << endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int N;cin>>N;
    string s,t;cin>>s>>t;
    string ans="";
    rep(i,N){
        ans+=s.at(i);
        ans+=t.at(i);
    }
    cout<<ans<<endl;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    vector<int> a(n);
    vector<int> b(n);
    for(int in=0;in<n;++in) {
        cin >> a[in];
    }
    for(int in=0;in<n;++in) {
        cin >> b[in];
    }

    int j = 0, bef = -1;
    for(int in=0;in<n;++in) {
        if(bef!=a[in]) j = 0;
        if(a[in]==b[in]) {
            for(;j<n;++j) {
                if(a[j]!=a[in]&&b[j]!=a[in]) {
                    swap(b[in], b[j]);
                    break;
                }
            }
            if(a[in]==b[in]) {
                cout << "No" << endl;
                return 0;
            }
        }
        bef = a[in];
    }
    
    cout << "Yes" << endl;
    for(int in=0;in<n;++in) {
        if(in) cout << " ";
        cout << b[in];
    }
    cout << endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size(), total=0;
  rep(i,n){
    total += s[i]-'0';
  }
  cout << ((total%9 == 0)?"Yes":"No") << endl;
  return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string res = "YES";
    int t = (int) s.size();
    while (t > 0) {
        if (s.substr(max(t - 5, 0), 5) == "dream") {
            t -= 5;
            continue;
        }
        if (s.substr(max(t - 5, 0), 5) == "erase") {
            t -= 5;
            continue;
        }   
        if (s.substr(max(t - 7, 0), 7) == "dreamer") {
            t -= 7;
            continue;
        }
        if (s.substr(max(t - 6, 0), 6) == "eraser") {
            t -= 6;
            continue;
        }
        res = "NO";
        break;
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 512
N = input()
K = int(input())
L = len(N)

# dp1 = the higest digit is 0, dp2 = the highest digit is not 0
dp1 = [[0] * (K+1) for _ in range(L+1)]
dp2 = [[0] * (K+1) for _ in range(L+1)]
for i in range(L+1):
    dp1[i][0] = 1
    for j in range(1, K+1):
        dp1[i][j] = dp1[i-1][j] + dp2[i-1][j]
        dp2[i][j] = 9 * (dp1[i-1][j-1] + dp2[i-1][j-1])
ans = dp1[L][K] + dp2[L][K]
d = K
for i in range(L):
    if N[i] != '0':
        ans -= dp2[L-i][d] * (9-int(N[i])) // 9
        d -= 1
    else:
        ans -= dp2[L-i][d]
    if d == 0:
        break
print(ans)


Measured memory_bytes: 3064
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

const ll mod = 998244353;
ll raise(ll a, ll b) { return b ? raise(a*a%mod,b/2)*(b%2?a:1)%mod : 1; }

int main() {
	int n, m, k; cin >> n >> m >> k;
	if(m == 1) { if(n <= k+1) println(1); else println(0); return 0; }
	ll res = raise(m-1, mod-2), x = 0, rem = raise(m-1, n-1);
	forl(i, 0, k+1) {
		x += rem;
		rem = (rem*(n-1-i))%mod;
		rem = (rem*raise(i+1, mod-2))%mod;
		rem = (rem*res)%mod;
	}
	x = ((x%mod)*m)%mod;
	println(x);
}


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

using namespace std;

int main(){

	char buf[81],result[81];
	bool FLG;
	short length;

	while(fgets(buf,81,stdin)!=0){
		FLG = false;
		length = 0;
		for(int i=0;buf[i]!='\0';i++)length++;
		for(int i=0;i<=25;i++){ //?????????????????°
			for(int k=0;buf[k]!='\0';k++){
				if(buf[k] >= 97 && buf[k] <= 122){
					if(buf[k]+i<=122){
						result[k]=buf[k]+i;
					}else{
						result[k]=97+(buf[k]+i-123);
					}
				}else{
					result[k]=buf[k];
				}
				result[k+1]='\0';
			}
			for(int k=0;result[k]!='\0';k++){
				// the this that ????????????????????????????????????
				if(length==4){
					if(result[0]=='t'&&result[1]=='h'&&result[2]=='e'&&result[3]=='.'){
						FLG=true;
						break;
					}
				}else{
					//??????
					if(result[0]=='t'&&result[1]=='h'&&result[2]=='e'&&result[3]==' '){
						FLG=true;
						break;
					}else if(result[0]=='t'&&result[1]=='h'&&result[2]=='i'&&result[3]=='s'&&result[4]==' '){
						FLG=true;
						break;
					}else if(result[0]=='t'&&result[1]=='h'&&result[2]=='a'&&result[3]=='t'&&result[4]==' '){
						FLG=true;
						break;
					}

					//????°?
					if(result[length-1]=='.'&&result[length-2]=='e'&&result[length-3]=='h'&&result[length-4]=='t'&&result[length-5]==' '){
							FLG=true;
							break;
					}
					if(length>5&&result[length-1]=='.'&&result[length-2]=='s'&&result[length-3]=='i'&&
							result[length-4]=='h'&&result[length-5]=='t'&&result[length-6]==' '){
							FLG=true;
							break;
					}else if(length>5&&result[length-1]=='.'&&result[length-2]=='t'&&result[length-3]=='a'&&
							result[length-4]=='h'&&result[length-5]=='t'&&result[length-6]==' '){
							FLG=true;
							break;
					}


					for(int p=4;result[p]!='\0';p++){
						if(result[p]==' ' && result[p-1] == 'e' && result[p-2] == 'h' && result[p-3] == 't' && result[p-4] == ' '){
							FLG = true;
							break;
						}
					}
					if(FLG)break;
					for(int p=5;result[p]!='\0';p++){
						if(result[p]==' ' && result[p-1] == 's' && result[p-2] == 'i' && result[p-3] == 'h' && result[p-4] == 't' && result[p-5] == ' '){
							FLG = true;
							break;
						}
					}
					if(FLG)break;
					for(int p=5;result[p]!='\0';p++){
						if(result[p]==' ' && result[p-1] == 't' && result[p-2] == 'a' && result[p-3] == 'h' && result[p-4] == 't' && result[p-5] == ' '){
							FLG = true;
							break;
						}
					}
					if(FLG)break;
				}
			}
			if(FLG)break;
		}
		printf("%s",result);

	}

    return 0;
}

Measured memory_bytes: 2648
N = int(input())
original = list(map(int, input().split()))
odd = [i for i in original if i % 2 != 0]
ans = 3 ** (len(original))
if len(odd) != len(original):
    ans -= 2**(len(original)-len(odd))
else:
    ans -= 1
print(ans)


Measured memory_bytes: 2940
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    String t = sc.next();
    String ss[] = s.split("");
    String tt[] = t.split("");
    Arrays.sort(ss);
    Arrays.sort(tt);
    s = String.join("",ss);
    t = String.join("",tt);
    int n = Math.min(s.length(),t.length());
    String ans = "No";
    int c = 0;
    for(int i = 0 ; i < n ; ++i){
      if((int)s.charAt(i)<(int)t.charAt(t.length()-i-1)){
        ans = "Yes";
        break;
      }else if((int)s.charAt(i)==(int)t.charAt(t.length()-i-1)){
        c++;
      }
    }
    
    if(c==n && s.length()<t.length()) ans ="Yes";
    
    System.out.println(ans);

  }
}

Measured memory_bytes: 35376
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String input = sc.next();
        char[] values = input.toCharArray();
        int a,b,c,d;
        a = values[0] - 48;
        b = values[1] - 48;
        c = values[2] - 48;
        d = values[3] - 48;

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 2; k++) {

                    int sum = a;
                    sum += (i == 0) ? 0 - b : b;
                    sum += (j == 0) ? 0 - c : c;
                    sum += (k == 0) ? 0 - d : d;

                    if (sum == 7) {
                        String ab = (i == 0) ? "-" : "+";
                        String bc = (j == 0) ? "-" : "+";
                        String cd = (k == 0) ? "-" : "+";
                        System.out.println(a + ab + b + bc + c + cd + d + "=7");
                        return;
                    }
                }
            }
        }
    }

}

Measured memory_bytes: 23124
import java.util.Scanner;


public class Main {

    public static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args) {

		int d = scanner.nextInt();
		int n = scanner.nextInt();
		if(n == 100) {
			n++;
		}
		System.out.println((int)Math.pow(100, d) * n);			

	}

}


Measured memory_bytes: 22612
o = io.read()
e = io.read()
for i = 1, #e do
  io.write(string.sub(o, i, i))
  io.write(string.sub(e, i, i))
end
if(#e < #o) then
  io.write(string.sub(o, #o, #o))
end
io.write("\n")


Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

// pairについてfirstは昇順、secondは降順ソートする
bool my_compare(pair<string, int> a, pair<string, int> b) {
  // 基本はfirstで比較
  if(a.first != b.first){
    return a.first < b.first; // 昇順
    // return a.first > b.first; // 降順
  }
  // それ以外はsecondで比較
  if(a.second != b.second){
    return a.second > b.second; // 降順
  }
  else {
    // どちらも同じ
    return true;
  }
}

int main() {
  int N;
  cin >> N;
  vector<pair<string, int>> SP(N);
  for (int i=0; i<N; i++) cin >> SP[i].first >> SP[i].second;
  vector<pair<string, int>> SP_copy = SP;
  sort(SP_copy.begin(), SP_copy.end(), my_compare);
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      if (SP[j].first==SP_copy[i].first&&SP[j].second==SP_copy[i].second) cout << j+1 << endl;
    }
  }
}

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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct UnionFind {
  vector<int> data;

  UnionFind(int n){
    data.resize(n+1);
    fill(data.begin(), data.end(), -1);
  }

  int root(int x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);

    if(rx!=ry){
      if(data[ry] < data[rx])swap(rx, ry);

      data[rx]+=data[ry];
      data[ry]=rx;
    }
  }

  bool same(int x, int y){
    return root(x)==root(y);
  }

  int size(int x){
    return -data[root(x)];
  }
};

int main(){
  ll n;cin>>n;
  vector<pll> x(n),y(n);
  rep(i,n){
    cin>>x[i].first>>y[i].first;
    x[i].second=y[i].second=i;
  }

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  vector<pair<ll, pi>>edges;
  rep(i, n-1){
    ll xcost = abs(x[i].first-x[i+1].first);
    edges.push_back({xcost, {x[i].second, x[i+1].second}} );

    ll ycost = abs(y[i].first-y[i+1].first);
    edges.push_back({ycost, {y[i].second, y[i+1].second}} );
  }

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

  ll result = 0;
  UnionFind uf(n);
  for(auto p:edges){
    ll a=p.second.first;
    ll b = p.second.second;
    if(!uf.same(a, b)){
      result += p.first;
      uf.unite(a,b);
    }
  }

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 9584
#include<stdio.h>
#include<string.h>
int main(){
	char s[10];
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++){
		if(s[i]=='7'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

int main() {
    string s,t;
    cin >> s >> t;
    int count=0,mm=2000;
    for(int i=0;i<=s.size()-t.size();i++){
        count=0;
        for(int j=0;j<t.size();j++){
            if(s[i+j] != t[j])count++;
        }
        mm = min(mm,count);
    }
    cout << mm << endl;
    return 0;
}

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

int main() {
  string S;
  int K, i, Q;
  i=0;
  cin >> S >> K;
  
  while(K > 0){
    if(S.at(i)=='1'){
      Q = 1;
      K--;
    }
    else if(S.at(i)=='2'){
      Q = 2;
      break;
    }
    else if(S.at(i)=='3'){
      Q = 3;
      break;
    }
    else if(S.at(i)=='4'){
      Q = 4;
      break;
    }
    else if(S.at(i)=='5'){
      Q = 5;
      break;
    }
    else if(S.at(i)=='6'){
      Q = 6;
      break;
    }
    else if(S.at(i)=='7'){
      Q = 7;
      break;
    }
    else if(S.at(i)=='8'){
      Q = 8;
      break;
    }
    else if(S.at(i)=='9'){
      Q = 9;
      break;
    }
    i++;
  } 
  cout << Q <<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int x, y;
  int i, temp, r;

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

  if(x<y){
    temp=x;
    x=y;
    y=temp;
  }

  r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  printf("%d\n", y);
  

  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
int main(){
 
    ll n; cin >> n;
    ll arr[n];
    ll dp[n + 25] = {0};
    for(ll i = 0; i < n; ++i){
        cin >> arr[i];
    }
    dp[0] = 0;
    for(ll i = 1; i < n; ++i){
        dp[i] = min(dp[i - 1] + abs(arr[i]  - arr[i - 1]), dp[i - 2] +  abs(arr[i] - arr[i - 2]));
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 5160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int[] a;
        a = new int[100];

        int[] b;
        b = new int[100];

        int i = 0;

        while (true) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();

            if (a[i] == 0 && b[i] == 0)
                break;

            i++;
        }

        i = 0;
        while (true) {
            for (int j = 0; j < b[i]; j++) {
                System.out.print("#");
            }
            System.out.println();
            for (int j = 0; j < a[i] - 2; j++) {
                System.out.print("#");
                for (int k = 0; k < b[i]-2; k++) {
                    System.out.print(".");
                }
                System.out.println("#");
            }
            for (int j = 0; j < b[i]; j++) {
                System.out.print("#");
            }
                System.out.println('\n');
            i++;
            if (a[i] == 0 && b[i] == 0)
                break;
        }
    }
}



Measured memory_bytes: 33920
import java.util.*;
import java.math.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		
		int n = scan.nextInt();
		// while(n-->0){}
		for(int i = 0; i < n; i++){
			double xa = scan.nextDouble();
			double ya = scan.nextDouble();
			double ra = scan.nextDouble();
			double xb = scan.nextDouble();
			double yb = scan.nextDouble();
			double rb = scan.nextDouble();
			double l = Math.sqrt((xb- xa) * (xb - xa) + (yb- ya) * (yb - ya));
			if(l > ra + rb){
				System.out.printf("%d\n", 0);
			} else if(ra > l + rb){
				System.out.printf("%d\n", 2);
			} else if(rb > l + ra){
				System.out.printf("%d\n", - 2);
			} else{
				System.out.printf("%d\n", 1);
			}
		}
	}
}

Measured memory_bytes: 28400
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;

int main()
{
	ll n, m;

	while( cin >> n >> m && (n || m)){

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

		targets.push_back(0);
		sort(targets.begin(), targets.end());
		targets.erase(unique(targets.begin(), targets.end()), targets.end());
		targets.erase(upper_bound(targets.begin(), targets.end(), m), targets.end());

		vector<ll> a1;

		for(int i = 0; i < targets.size(); i++)
			for(int j = 0; j < targets.size(); j++)
				a1.push_back(targets[i] + targets[j]);

		sort(a1.begin(), a1.end());
		a1.erase(unique(a1.begin(), a1.end()), a1.end());

		ll res = 0;

		for(int i = 0; i < a1.size(); i++)
		{
			vector<ll>::iterator it = upper_bound( a1.begin(), a1.end(), m - a1[i]);
			if(it != a1.begin()){
				it--;
				res = max(res, a1[i] + (*it));
			}
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    vector<int> hai_p(s.size());
    int del,s_del=753,n;
    for(int i=0;i<s.size()-2;i++){
        n = (s.at(i)-'0')*100 +(s.at(i+1)-'0')*10+(s.at(i+2)-'0');
        del = abs(753-n); 
        if (s_del>del){
            s_del = del;
        }
    }
    cout << s_del <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)


int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > > q;
    pair<long long, long long> p;
    rep(i,n){
        cin >> p.first >> p.second;
        q.push(p);
    }
    long long res = 0;
    long long count = 0;
    rep(i,n){
        long long sumall = q.top().first*q.top().second;
        if (count+q.top().second < m){
            res += sumall;
            count += q.top().second;
        }
        else{
            res += q.top().first*(m-count);
            break;
        }
        q.pop();
    }
    cout << res << endl;
    
    
    return 0;
}


Measured memory_bytes: 3444
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

int main()
{
    ll n=in(),t=in(),a=in();
    REP(i,n-1){
        ll ti=in(),ai=in();
        t=(t+ti-1)/ti*ti;
        a=(a+ai-1)/ai*ai;
             if(t/ti<a/ai)t=a/ai*ti;
        else if(t/ti>a/ai)a=t/ti*ai;
    }
    cout<<(t+a)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		int d = a / b;
		int r = a % b;
		double f = a * 1.0 / b;
		
		//System.out.println(d + " " + r + " " + f);
		System.out.printf("%d %d %16.5f", d, r, f);
	}

}



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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    string s;
    cin >> s;

    bool f = false;

    if (s[0] == s[1] && s[1] == s[2])
        f = true;
    if (s[1] == s[2] && s[2] == s[3])
        f = true;

    if (f)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<" L-B-W-- "<<x<<" --N-B\n"
#define pb push_back
//#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
const double pai = acos(-1.0);
const double eps = 1e-8;
const int mod=998244353;
//const int mod=1e9+7;
const int inf=1e9+7;
//const ll inf=0x7f7f7f7f1234abcd;
const int maxn=1e5+10;
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;x=x*x%mod; y>>=1;} return res; }
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}
ll lcm(ll a, ll b) { return a * b / __gcd(a, b); }

int t,n,m,k;
int f;
int a[maxn];
vii ve[maxn];
int main(){
    scanf("%d%d",&n,&m);
    rep(i,1,n) scanf("%d",&a[i]);
    rep(i,1,m){
        scanf("%d%d",&f,&t);
        ve[f].pb(t);
        ve[t].pb(f);
    }
    int s=0;
    rep(i,1,n){
        if(ve[i].size()==0) {s++;continue;}
        bool f=1;
        for(auto g:ve[i]){
            if(a[g]>=a[i]) f=0;
        }
        s+=f;
    }
    printf("%d\n",s);
    return 0;
}


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

int main()
{
    char ch;
    cin>>ch;
    for(char ch1='a';ch1<='z';++ch1)
    {
        if(ch1==ch)
        {
            cout<<'a';
            return 0;
        }
    }
    cout<<'A';
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  cin.ignore();
  while (n--) {
    string s; getline(cin, s);
    int k = -1;
    VV<> a(4, V<>(4, -1));
    for (int i = 0; i < 4; ++i) {
      getline(cin, s);
      if (s[0] == '*') k = i;
      for (int j = i + 1; j < 4; ++j) {
        if (isdigit(s[5 * j + 6])) {
          a[i][j] = s[5 * j + 6] - '0';
          a[j][i] = s[5 * j + 8] - '0';
        }
      }
    }
    auto qualifies = [&](const VV<>& a) -> double {
      V< VV<> > p(4);
      for (int _ = 0; _ < 3; ++_) {
        VV<> v(4, V<>(3));
        bitset<4> bs;
        for (int s = 0; s < 4; ++s) if (!bs[s]) {
          V<> idx;
          for (int i = 0; i < 4; ++i) if (p[s] == p[i]) {
            bs[i] = true;
            idx.push_back(i);
          }
          for (int i : idx) for (int j : idx) if (i < j) {
            if (a[i][j] > a[j][i]) v[i][0] += 3;
            else if (a[i][j] < a[j][i]) v[j][0] += 3;
            else ++v[i][0], ++v[j][0];
            v[i][1] += a[i][j] - a[j][i];
            v[j][1] += a[j][i] - a[i][j];
            v[i][2] += a[i][j];
            v[j][2] += a[j][i];
          }
        }
        for (int i = 0; i < 4; ++i) p[i].push_back(v[i]);
      }
      int u = 0, m = 0, l = 0;
      for (int i = 0; i < 4; ++i) if (i != k) {
        u += p[i] > p[k];
        m += p[i] == p[k];
        l += p[i] < p[k];
      }
      if (u >= 2) return 0;
      if (l >= 2) return 1;
      if (m == 3 or m == 1) return 0.5;
      return u ? 1.0 / 3 : 2.0 / 3;
    };
    auto comb = [](int n, int r) -> int {
      int res = 1;
      for (int i = 1; i <= r; ++i) {
        res *= n - r + i;
        res /= i;
      }
      return res;
    };
    double res = 0;
    V<> v;
    auto dfs = [&](const auto& dfs) -> void {
      if (v.size() == 4) {
        auto itr = begin(v);
        auto b = a;
        for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) if (i != j and b[i][j] == -1) {
          b[i][j] = *itr++;
        }
        double p = 1;
        for (int e : v) {
          p *= comb(8, e) * pow(0.25, e) * pow(0.75, 8 - e);
        }
        res += p * qualifies(b);
        return;
      }
      for (int x = 0; x <= 8; ++x) {
        v.push_back(x);
        dfs(dfs);
        v.pop_back();
      }
    };
    dfs(dfs);
    cout << fixed << setprecision(15) << res << '\n';
  }
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int a, b;
    cin >> a >> b;
    cout << ( a + b == 15 ? '+' : a * b == 15 ? '*' : 'x' ) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

using namespace std;

struct Info {
  int v;
  int nEdge;
  Info(int v) : v(v) {
    // implement HERE for additional informations
    nEdge = 0;
  }
};
struct UF {
  vector<Info> data;
  int nDistinct;
  UF() {}
  UF(int n) : data(n, -1), nDistinct(n) {}
  void init(int n) { data.assign(n, -1); nDistinct = n; }
  int size(void) const { return nDistinct; }
  int rootOf(int a) { return data[a].v >= 0 ? data[a].v = rootOf(data[a].v) : a; }
  int count(int a) { return -data[rootOf(a)].v; }
  bool isSameGroup(int a, int b) { return rootOf(a) == rootOf(b); }
  bool unify(int a, int b) {
    int ra = rootOf(a), rb = rootOf(b);
    if(ra == rb) {
      // implement HERE for additional informations
      data[ra].nEdge++;
      return false;
    }
    if(data[ra].v < data[rb].v) swap(ra, rb);
    data[rb].v += data[ra].v;
    // implement HERE for additional informations
    data[rb].nEdge += data[ra].nEdge + 1;
    data[ra].v = rb;
    --nDistinct;
    return true;
  }
};

struct K {
  int r, c;
  ll a;
};
K vs[100000+5];
bool operator<(const K &k1, const K &k2) {
  return k1.a < k2.a;
}

int main(void) {
  int n, h, w;
  scanf("%d%d%d", &n, &h, &w);
  REP(i, n) {
    scanf("%d%d%lld", &vs[i].r, &vs[i].c, &vs[i].a);
    --vs[i].r;
    --vs[i].c;
  }
  sort(vs, vs + n);
  reverse(vs, vs + n);
  UF uf(h+w);
  ll res = 0;
  REP(i, n) {
    const K &cur = vs[i];
    int r1 = uf.rootOf(vs[i].r);
    int r2 = uf.rootOf(h+vs[i].c);
    Info &info1 = uf.data[r1];
    Info &info2 = uf.data[r2];
    if(r1 == r2) {
      int nNode = -info1.v;
      int nEdge = info1.nEdge;
      if(nEdge+1 <= nNode) {
        // cerr << "> " << cur.a << endl;
        res += cur.a;
        uf.unify(r1, r2);
      }
    } else {
      int nNode = -info1.v -info2.v;
      int nEdge = info1.nEdge + info2.nEdge;
      if(nEdge+1 <= nNode) {
        // cerr << "> " << cur.a << endl;
        res += cur.a;
        uf.unify(r1, r2);
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 2e5+10;
const ll INF = 1e18;
const ll MOD = 1e9+7;

ll tree[4*MAX],a[MAX],h[MAX];

void update(int node, int start, int end, int idx, ll val)
{
    if(start == end)
        tree[node] = val;
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
            update(2*node, start, mid, idx, val);
        else
        
            update(2*node+1, mid+1, end, idx, val);
        tree[node] = max(tree[2*node], tree[2*node+1]);
    }
}

ll query(int node, int start, int end, int l, int r)
{
    if(r < start or end < l)
        return 0;
    if(l <= start and end <= r)
        return tree[node];
    int mid = (start + end) / 2;
    ll p1 = query(2*node, start, mid, l, r);
    ll p2 = query(2*node+1, mid+1, end, l, r);
    return max(p1 , p2);
}

int main()
{
    int n,i,j,k;
    ll ans,l;
    cin >> n;
    for(i=0;i<n;i++)
        cin >> h[i];
    for(i=0;i<n;i++)
        cin >> a[i];
    ans = 0;
    for(i=0;i<n;i++)
    {
        l = query(1,1,n,1,h[i]-1)+a[i];
        ans = max(l,ans);
        update(1,1,n,h[i],l);
    }
    cout << ans;
}

Measured memory_bytes: 10812
n = int(input())
H = list(map(int,input().split()))

ans = 0
c = 0
for i in range(len(H)):
    if i == len(H)-1:
        print (ans) if c < ans else print (c)
    else:
        if H[i+1] <= H[i]:
            c += 1
        else:
            if ans < c:
                ans = c
            c = 0



Measured memory_bytes: 14252
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int x = 0;

		if (a >= 1 && a < b) {
			x = (b - a) * (b - a + 1) / 2 - b;
		} else {
			return;
		}
		System.out.println(x);

	}
}

Measured memory_bytes: 21972
N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

tentou = 0
for i in range(N):
    for j in range(i, N):
        if A[i] > A[j]:
            tentou += 1

A_sorted = sorted(A)
smaller = [0] * N
for i in range(1, N):
    if A_sorted[i - 1] < A_sorted[i]:
        smaller[i] = i
    else:
        smaller[i] = smaller[i-1]
sum_smaller = sum(smaller)

ans = (((tentou * K) % mod) + ((sum_smaller * (((K * (K - 1)) // 2) % mod)) % mod)) % mod
print(ans)


Measured memory_bytes: 41436
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 16, maxmask = 1ll << 16;

int n, a[maxn][maxn], dp[maxmask];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> a[i][j];
    for(int i = 0; i < (1 << n); i++)
    {
        for(int j = 0; j < n; j++)
            for(int k = j + 1; k < n; k++)
                if((i & (1ll << j)) && (i & (1ll << k)))
                    dp[i] += a[j][k];
        for(int j = i; j > 0; j = (j - 1) & i)
            dp[i] = max(dp[i], dp[j] + dp[i ^ j]);
    }
    cout << dp[(1 << n) - 1] << "\n";
    return 0;
}

Measured memory_bytes: 4120
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  string a;
  cin>>a;
  for(char i='a';i<='z';i++){
  int c=0;
    rep(j,a.size()){
  if(a[j]==i)
    c++;
  }
    if(c==0){
    cout<<i<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#define rep(i,n) for(i=0;i<n;i++)
int main(void)
{
  int w,h,i,j,x,y;
  char f[100][100],t;
  for(;;){
    scanf("%d%d",&h,&w);if(!w)break;
    rep(i,h)rep(j,w)scanf(" %c",f[i]+j);x=y=0;
    for(;;){
      if(f[y][x]=='*'){puts("LOOP");goto END;}
      if(f[y][x]=='.'){printf("%d %d\n",x,y);goto END;}
      t=f[y][x];f[y][x]='*';
      switch(t){
      case '>':x++;break;
      case '<':x--;break;
      case 'v':y++;break;
      case '^':y--;break;
      }
    }
  END:;
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
li_a = map(int, input().split())
total = 1
kisuu = 1
for a in li_a:
    if a == 0:
        total *= 2
        kisuu *= 1
    else:
        total *= 3
        if a % 2 == 1:
            kisuu *= 1
        else:
            kisuu *= 2
print(total - kisuu)


Measured memory_bytes: 2940
//Ants on a Circle
//CodeForces_652F
//18.10.03
#include<cstdio>
#include<iostream>
#include<algorithm>

const int MAXN=100000+10;

int Read(){
	char ch;
	while((ch=getchar())<48||57<ch);
	int ans=ch-48;
	while(48<=(ch=getchar())&&ch<=57)
		ans=(ans<<3)+(ans<<1)+ch-48;
	return ans;
}

int x[MAXN];
int w[MAXN];

int main(){
#ifdef EagleBear
	freopen("Ants on a Circle.in","r",stdin);
//	freopen("Ants on a Circle.out","w",stdout);
#endif

	int n=Read();
	int l=Read();
	int t=Read();
	for(int i=1;i<=n;++i)
		x[i]=Read(),w[i]=Read();
	
	int cross_cnt=0;
	for(int i=1;i<=n;++i)
		w[i]==1?x[i]+=t:x[i]-=t;
		
	for(int i=1;i<=n;++i){
		cross_cnt+=x[i]>=0?x[i]/l:(x[i]+1)/l-1;
		x[i]=(x[i]%l+l)%l;
	}
	
//	std::cout<<"cross_cnt="<<cross_cnt<<std::endl;
	std::sort(x+1,x+n+1);
	for(int i=1;i<=n;++i){
		int k=(i+cross_cnt%n+n)%n;
		if(k==0) k=n;
		printf("%d\n",x[k]);
	}
	
	return 0;
}



Measured memory_bytes: 1920
//Sasayego! Sasayego! Shinzou wo Sasageyo!

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x)  cerr << #x << " = " << x << endl
#define lid (id << 1)
#define rid (lid ^ 1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll len(pll X){
	return X.second - X.first;
}

pll I (pll X, pll Y){
	pll Z;
	Z.first = max(X.first, Y.first);
	Z.second = min(X.second, Y.second);
	if (Z.first >= Z.second)
		Z = {-1, -1};
	return Z;
}

pll U (pll X, pll Y){
	pll Z;
	Z.first = min(X.first, Y.first);
	Z.second = max(X.second, Y.second);
	return Z;
}

int main(){
	time_t START = clock();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll a, b; scanf("%lld%lld", &a, &b);
	if (a == b)
		return printf("1\n"), 0;
	int ix = 63 - __builtin_clzll(a ^ b);
	ll p = (1ll << ix);
	ll c = a & (p - 1);
	ll d = b & (p - 1);
	int tmp = (d ? 64 - __builtin_clzll(d) : 0);
	pll A = {p, p + (1ll << tmp)};
	pll B = {p + c, p << 1};
	ll ans = len({c, p}) + (I(A, B).first == -1 ? len(A) + len(B) : len(U(A, B)));
	printf("%lld\n", ans);
	time_t FINISH = clock();
	cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
	return 0;
}
 



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

int main() {
	int n1,n2,c=0,i;
	string s1,s2,s3;
	cin>>s1>>s2>>n1>>n2>>s3;
	for(i=0;i<s3.length();i++)
	if(s3[i]==s1[i])
	c++;
	if(c==s3.length())
	n1--;
	else
	n2--;
	cout<<n1<<" "<<n2;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.StringBuilder;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		StringBuilder bu = new StringBuilder();
		int h,w;
		while((h=sc.nextInt())!=0&&(w=sc.nextInt())!=0){
			for(int i=0;i<h;i++){
				for(int o=0;o<w;o++){
					bu.append("#");
				}
				bu.append("\n");
			}
			bu.append("\n");
		}
		System.out.print(bu);
	}
}

Measured memory_bytes: 27636
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
          ans -= sc.nextInt() - sc.nextInt() - 1; 
        }
    
		// 出力
		System.out.println(ans);
	}
}

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

int main()
{
    int n, m;
    cin >>n>>m;
    vector<long long>a;
    int bef;
    int bef2;
    map<long long,long long>ing;
    ing[0]=1000000;
        for(int i=0;i<n;i++){
        cin >> bef;
        a.push_back(bef);
    }
    sort(a.begin(),a.end());
    for(int i=0;i<m;i++){
        cin >>bef>>bef2;
        ing[bef2]+=bef;
        //ing.insert(make_pair(bef2,bef));
    }
    long long ans=0;
    auto itr=ing.end();
    itr--;
    bool com=true;
    for(int i=0;i<n;i++){
     //   cout<<ing.size()<<"     --";
      //  cout<<a[i]<<"   "<<itr->first<<" "<<itr->second<<endl;
        if(ing.size()==0){
            com=false;
            //goto comed;
        }
        if(a[i] <itr->first){
            ans+=itr->first;
            if(itr->second!=1){
                itr->second-=1;
            }else{
               
                ing.erase(itr);
                itr=ing.end();
                itr--;
            }

        }else{
        
            ans+=a[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7284
#include <iostream>
int main(){
  int h,w,n,a[10001];
  std::cin>>h>>w>>n;
  int c[101][101];
  int h1=0, w1=0;
  for(int i=0;i<n;++i){
    std::cin>>a[i];
    while(a[i]>0){
      a[i]--;
      c[h1][w1]=i+1;
      w1++;
      if(w1==w){
        w1=0;
        h1++;
      }
    }
  }

  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(i%2==0)std::cout<<c[i][j];
      else std::cout<<c[i][w-1-j];
      if(j!=w-1)std::cout<<" ";
    }
    std::cout<<std::endl;
  }

}


Measured memory_bytes: 384
#include<stdio.h>

int main()
{
	int w;
	char s[1001]={};

	scanf("%s",s);
	scanf("%d",&w);

	int cnt=0;
	for(int a=0;a<1000;a=a+w)
	{
		if(s[a]!='\0')printf("%c",s[a]);
		else break;
	}
	printf("\n");

	return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    ll n;
    cin >> n;
    ll ans = (n - 1) * n / 2;
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3608
using System;
using System.Linq;

namespace aizu
{
    public class OnlineJudge
    {
        static void Main()
        {
            (from p in Enumerable.Range(1, int.Parse(Console.ReadLine())) let input = Console.ReadLine().Split() group new { k = input[0], v = int.Parse(input[1]) } by input[0] into q orderby q.Key.Length, q.Key select new { k = q.Key, v = q.Sum(i => i.v) }).ToList().ForEach(item => Console.WriteLine("{0} {1}", item.k, item.v));
        }
    }
}

Measured memory_bytes: 8416
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		int n = sc.nextInt();
		int sft[] = createSft(n);
		int cnt = 0;
		for(int i = 0; i < 30000; i++) {
			if(sft[i] <= n) cnt++;
			else break;
		}
		System.out.println(cnt);
	}
	
	int[] createSft(int n) {
		int num[] = new int[30000];
		Arrays.fill(num, 1000000000);
		int idx = 0;
		for(int i = 3; i < 10; i++) {
			for(int j = 0; j < Math.pow(3, i); j++) {
				String s = "000000000" + Integer.toString(j, 3);
				String sS = s.replace('2', '7');
				String sF = sS.replace('1', '5');
				String sT = sF.replace('0', '3');
				String ans = sT.substring(s.length() - i);
				if(ans.indexOf('3') >= 0 && ans.indexOf('5') >= 0 && ans.indexOf('7') >= 0) {
					num[idx] = Integer.parseInt(ans);
					idx++;
				}
			}
		}
		return num;
	}
	public static void main(String[] args) {
		new Main().doIt();
	}

}


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

int main(){
  int N,M;
  cin >> N >> M;
  int a=0;
  int b=0;
  int num[N];
  for (int i=0;i<N;i++){
    num[i]=0;
  }
  
  for (int i=0;i<M;i++){
    cin >> a >> b;
    num[a-1]++;
    num[b-1]++;
  }

  for (int i=0;i<N;i++){
    cout<<num[i]<<endl;
  }
  return 0;
}


  

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
int a[N],b[N],c[N],d[N],fa[N],n,tot,res;map<int,int>mp;
inline int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline int ID(R int x){return mp[x]?mp[x]:mp[x]=++tot;}
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]),a[n+1]^=a[i];
	fp(i,1,n)scanf("%d",&b[i]),b[n+1]^=b[i];
	fp(i,1,n+1)c[i]=a[i],d[i]=b[i];
	sort(c+1,c+2+n),sort(d+1,d+2+n);
	fp(i,1,n+1)if(c[i]!=d[i])return puts("-1"),0;
	fp(i,1,n+1)fa[i]=i;
	fp(i,1,n)if(a[i]!=b[i]){
		R int u=ID(a[i]),v=ID(b[i]);
		fa[find(u)]=find(v),++res;
	}
//	puts("qwq");
	if(!res)return puts("0"),0;
	fp(i,1,tot)if(find(i)==i)++res;
	bool fl=1;
	fp(i,1,n)if(b[i]==a[n+1])fl=0;
	printf("%d\n",res+fl-1);
	return 0;
}

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

using namespace std;

typedef long long ll;

double getTime() { 
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int n; read(n);
  vector <int> p(n);
  for(int i = 0; i < n; i++) {
    read(p[i]);
  }
  int mn = 1e9; int ans = 0;
  for(int i = 0; i < n; i++) {
    if(mn >= p[i]) ans++;
    mn = min(mn, p[i]);
  }
  print(ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

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

void solve_D_re_re(){
    ll n;
    cin >> n;
    ll r = 0, g = 0, b = 0;
    string s;
    cin >> s;
    REP(i,n){
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;
    }

    ll ctr = 0;
    for(ll i = 0; i < n; i++){
        for(ll j = i + 1; j < n; j++){
            ll k = 2 * j - i;
            if(k >= n || s[i] == s[j] || s[j] == s[k] || s[k] == s[i]) continue;

            ctr++;
        }
    }

    cout << r * g * b - ctr << endl;
}

int main(void){
    solve_D_re_re();
    
    return 0;
}

Measured memory_bytes: 3640
import sys
from itertools import compress


def is_right_order(B, C):
    max_val = 0
    for b in B:
        if b < max_val:
            return False
        max_val = b

    max_val = 0
    for c in C:
        if c < max_val:
            return False
        max_val = c
    return True


def solve_bf(d):
    """ ??????????????§?§£??? """
    for i in range(1024):
        bin_i = '{0:010b}'.format(i)
        bin_i = [int(x) for x in bin_i]
        comp = compress(d, bin_i)
        B = list(comp)
        C = d[:]
        for b in B:
            C.remove(b)
        if is_right_order(B, C):
            return True
    return False



if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    data = []
    for _ in range(num):
        data.append(list(map(int, input().split(' '))))

    # ????????????
    for d in data:
        result = solve_bf(d)

        # ???????????¨???
        if result:
            print('YES')
        else:
            print('NO')

Measured memory_bytes: 7692
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

int a[100010];
int sum[100010];
int SUM=0;
bool dp[5010][5010];
int main(){
	int n,k;
	cin>>n>>k;	
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int x;
	if(a[n-1]>=k){x=lower_bound(a,a+n,k)-a;}
	else x=n;
	for(int i=0;i<x;i++){
	    SUM+=a[i];
	    sum[i]=SUM;
	}
	for(int i=0;i<n;i++)
		for(int j=0;j<=k;j++)dp[i][j]=false;
	
	
	int i=x;
	if(sum[x-1]<k)goto hoge;
	dp[x-1][0]=true,dp[x-1][a[x-1]]=true;
	
	for(i=x-2;i>=1;i--){
	    bool flag=true;
	    for(int j=k;j>=0;j--){
	        if(j>=a[i] && dp[i+1][j-a[i]]){
		   dp[i][j]=true;
		   //cout<<i<<","<<j<<endl;
		   if(flag){
		      if(k-sum[i-1]>j || k==j)goto hoge;
		      flag=false;
		   }
		}   
	    }
        }
	hoge:
	
	cout<<i<<endl;
	return 0;
}

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

int main() {
  int N,A,a=100,b=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A;
    while(A%2==0){
      A /= 2;
      b++;
    }
    if(a>b){
      a=b;
      b=0;
    }
    else{
      b=0;
    }
  }
  cout << a <<endl;
}

Measured memory_bytes: 256