akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <unordered_map>
#include <vector>
#include <tuple>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define repeat(n) for(int __i=0;__i<n;__i++)
#define loop_from_to(from, to, i) for(int i=from;i<=to;i++)
#define multi_cin(n, array) loop(n,i){cin>>array[i];}
#define assign_if_smaller(var, val) if(var>val)var=val;
#define assign_if_larger(var, val) if(var<val)var=val;

using namespace std;
int x_size, y_size;
int x_min, x_max;
int y_min, y_max;
int type;
unordered_map<int, vector<tuple<int, int, int>>> sheets;

void init() {
  x_min = 0; y_min = 0; x_max = 0; y_max = 0;
  x_size = 0; y_size = 0;
}

void add_sheet(int x1, int y1, int x2, int y2) {
  assign_if_smaller(x_min, x1);
  assign_if_smaller(y_min, y1);
  assign_if_larger(x_max, x2);
  assign_if_larger(y_max, y2);
  x_size = x_max + 1;
  y_size = y_max + 1;

  auto t = make_tuple(y1, x2, y2);
  if (sheets.count(x1) == 0) {
    sheets[x1] = {t};
  } else {
    sheets[x1].push_back(t);
  }
}
vector<tuple<int, int, int>>& find_end_points(int x, int y) {
  return sheets[x];
}

void calc_and_output() {
  long area = 0;
  long lines = 0;

  int right_area_end_point[y_size];
  loop(y_size, i) right_area_end_point[i] = -1;

  bool* is_area[2];
  is_area[0] = new bool[y_size];
  is_area[1] = new bool[y_size];
  loop(y_size, i) {
    is_area[0][i] = false;
    is_area[1][i] = false;
  }

  loop(x_size, x_i) {
    // update right_area_end_point
    auto& points = find_end_points(x_i, 0);

    // per point operation
    for (auto&& point : points) {
      int y_i = get<0>(point), x = get<1>(point), y = get<2>(point);

      loop_from_to(y_i, y - 1, p_i) {
        assign_if_larger(right_area_end_point[p_i], x);
      }
    }

    loop(y_size, y_i) {

      // included in some sheets
      if (right_area_end_point[y_i] > x_i) {
        area += 1;
        is_area[x_i % 2][y_i] = true;
      } else {
        is_area[x_i % 2][y_i] = false;
      }

      // line check
      if (type == 2) {
        // left line exists
        if (is_area[(x_i % 2) ^ 1][y_i] != is_area[x_i % 2][y_i]) lines += 1;

        // bottom line exists
        if (
            (y_i == 0 && is_area[x_i % 2][y_i]) ||
            (y_i > 0 && (is_area[x_i % 2][y_i - 1] != is_area[x_i % 2][y_i]))
            )
          lines += 1;
      }
    }

  }

  cout << area << endl;
  if (type == 2) cout << lines << endl;

  delete is_area[0];
  delete is_area[1];
}

int main(int argc, char const* argv[])
{
  while (true) {
    int n; cin >> n >> type;
    if (n == 0 && type == 0) break;

    init();

    repeat(n) {
      int p[4];
      multi_cin(4, p);
      add_sheet(p[0], p[1], p[2], p[3]);
    }

    calc_and_output();
    sheets.clear();
  }
  return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep2(i, N, M) for (ll i = N; i < M; i++)
#define pb push_back



typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef priority_queue<pll, vector<pll>, greater<pll>> greater_pq;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>

template<class T, class S>
T atbit(T n, S i) {
	return (n >> i) % i;
}
template<class T>
T getbit( T i) {
	return 1LL<<i;
}

ll sum(ll M, ll  i) {
	if (M < 0) {
		cout << "";
	};
	if (!((M >> i) % 2 )) {
		return M + (1LL << i);
	}
	else if(!atbit(M,i+1)){
		return sum(M,i+2) - getbit(i) + getbit(i+1);
	}
	else {
		return M - getbit(i)-getbit(i+1);
	}
}

int main() {
	string S;
	ll K;
	cin >>S>> K;
	bool flg = true;
	ll x = 0;
	rep(i, K) { 
		if (S[i] != '1') {
			flg = false;
			cout<< S[i];
			return 0;
		}

	}
	
	cout << 1;
	



	return 0;
}



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

int main(){
  char a[200];
  int i;
  i=0;
  while(scanf("%c",&a[i])!=EOF)i++;
  for(int j=0;j<i;j++){
    if('a'<=a[j]&&a[j]<='z'){
      a[j]=a[j]-'a'+'A';
    }
    cout<<a[j];
  }
  //cout<< endl;
  
  return 0;
}

Measured memory_bytes: 1108
import math
def combination(n, r):
    if n <= 0 or n is 1:
        return 0
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

n, m= input().split(" ")
n = int(n)
m = int(m)

print(combination(n, 2) + combination(m,2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define lli long long int


int main() {
int a, b;
  cin>>a>>b;
  
  if(a>=1 && a<=9 && b>=1 && b<=9)
      cout<<a*b<<endl;
  else
       cout<<-1<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int n,A[100010];
bool fuck(){
	int c[2]={0},c1=0;
	for(int i=1;i<=n;++i)++c[A[i]&1],c1+=A[i]==1;
	if(c1||(c[0]&1))return c[0]&1;
	if(c[1]>1&&~c[0]&1)return 0;
	int g=0;
	for(int i=1;i<=n;++i){
		if(A[i]&1)--A[i];
		g=std::__gcd(g,A[i]);
	}
	for(int i=1;i<=n;++i)A[i]/=g;
	return!fuck();
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=gi();
	for(int i=1;i<=n;++i)A[i]=gi();
	if(fuck())puts("First");
	else puts("Second");
	return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();

		X -= 2 * Z + Y;
		System.out.println(X / (Y + Z) + 1);
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  char c;
  cin >> c;
  if('A' <= c && c <= 'Z'){
    cout << 'A' << endl;
  }else{
    cout << 'a' << endl;
  }
  return 0;
}

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

int main() {
  int n;
  int64_t sum = 1;
  cin >> n;
  vector<int64_t> a(n);
  for (int i = 0; i<n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i<n; i++) {
    if (a.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i<n; i++) {
    if (a.at(i) <= 1000000000000000000/sum) {
      sum *= a.at(i);
    }
    else {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << sum << endl;
}

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

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    vector<int64_t> A(N), B(M), SA(N+1), SB(M+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
        SA[i+1] = SA[i] + A[i];
    }
    for(int i=0; i<M; i++){
        cin >> B[i];
        SB[i+1] = SB[i] + B[i];
    }

    int ans = 0;
    for(int i=0; i<=N; i++) if(SA[i] <= K){
        int res = i;
        res += upper_bound(SB.begin(), SB.end(), K-SA[i]) - SB.begin() - 1;
        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){

    while(1){
        int b; cin >> b;
        if(b == 0) return 0;

        ll left = 1;
        ll right = 1;
        ll sum = 1;
        while(1){

            if(sum < b){
                right++;
                sum += right;
            }

            if(b < sum){
                sum -= left;
                left++;
            }

            if(b == sum){
                cout << left << " " << right - left + 1 << endl;
                break;
            }

        }

    }
}


Measured memory_bytes: 3020
def gcd(x,y):
    if x % y == 0:
        return y
    else:
        return  gcd(y, x%y)
A,B,C,D = list(map(int,input().split()))
LCD = C * D // gcd(C,D)

Bc = B // C
Bd = B // D
Blcd = B // LCD
Bans = B - Bc - Bd + Blcd 

A = A - 1
Ac = A // C
Ad = A // D
Alcd = A // LCD
Aans = A - Ac - Ad + Alcd

print(Bans - Aans)

Measured memory_bytes: 38256
z,*s=gets.split(/
|T/,-1).map &:size
Y=Z=1<<8e3
X=Y<<z
s.size%2>0&&s<<0
s.map{Y=Y>>_1|Y<<_1
X,Y=Y,X}
eval"puts X>>%d&Y>>%d&Z>0?:Yes: :No"%gets.split

Measured memory_bytes: 26884
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    N = len(S)
    M = 10 ** 5
    K = len(bin(M)) - 2

    A = [[0] * N for _ in range(K)]
    for i, c in enumerate(S):
        if c == 'R':
            A[0][i] = i + 1
        else:
            A[0][i] = i - 1

    for k in range(K - 1):
        for i in range(N):
            A[k + 1][i] = A[k][A[k][i]]

    B = list(range(N))
    for k in range(K):
        if M & (1 << k):
            for i in range(N):
                B[i] = A[k][B[i]]

    ans = [0] * N
    for b in B:
        ans[b] += 1

    print(*ans)
    return


if __name__ == '__main__':
    main()


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

typedef long long ll;
const int N=100000010;
char s[N];
ll dp[N];
ll sum[26],summ;
int main(){
   {
	scanf("%s",s+1);
	int n=strlen(s+1);
	dp[1]=1,summ=1;
	memset(sum,0,sizeof(sum));
	sum[s[1]-'a']++;
	for(int i=2;i<=n;i++){
		dp[i]=dp[i-1];
		dp[i]+=summ-sum[s[i]-'a'];
		sum[s[i]-'a']++;
		summ++;
	}
	printf("%lld\n",dp[n]);
   }
}

Measured memory_bytes: 3840
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

// https://atcoder.jp/contests/abc143/tasks/abc143_c
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		sc.close();

		String[] strArray = new String[N+1];
		for (int i = 0; i < N; i++) {
		    // strの先頭から1文字ずつString型にして取り出す
			strArray[i] = String.valueOf(S.charAt(i));
		}

		List<String> list = new ArrayList<String>();
		for(int i=0;i<N;i++) {
			String str = strArray[i];
			if(!(str.equals(strArray[i+1])&&(i+1)!=N)) {
				list.add(str);
			}
		}
		System.out.println(list.size());

	}
}


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

int main(){
  int H, W;
  cin >> H >> W;

  vector<vector<char>> data(H,vector<char>(W)); // データ
  vector<vector<char>> workA(H,vector<char>(W));// 作業用
  vector<vector<char>> workB(H,vector<char>(W));// 最終用

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> data.at(i).at(j);
    }
  }

  bool flag;
  // dataが横１行すべて「.」なら削除してworkAにコピーする
  int y = 0;
  for(int i = 0; i < H; i++){
    flag = true;
    for(int j = 0; j < W; j++){
      if(data.at(i).at(j) == '#'){
        flag = false;
        break;
      } 
    }
    if(!flag){
      for(int j = 0; j < W; j++){
        char tmp = data.at(i).at(j);
        workA.at(y).at(j) = tmp;
      }
      y++;
    }
  }

// workAが縦１行すべて「.」なら削除してworkBにコピーする
int x = 0;
for(int i = 0; i < W; i++){
    flag = true;
    for(int j = 0; j < y; j++){
      if(workA.at(j).at(i) == '#'){
        flag = false;
        break;
      } 
    }
    if(!flag){
      for(int j = 0; j < y; j++){
        char tmp = workA.at(j).at(i);
        workB.at(j).at(x) = tmp;
      }
      x++;
    }
  }

  //cout << endl;
  for(int i = 0; i < y; i++){
    for(int j = 0; j < x; j++){
      cout << workB.at(i).at(j);
    }
    cout << endl;
  }

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int W,N;
  int count = 0;
  while(cin >> W){
    if(W==0) break;
    cin >> N;
    count++;
    int item[W+1];
    for(int i=0;i<=W;i++) item[i] = 0;

    int v,w;
    char c;
    for(int i=0;i<N;i++){
      cin >> v >> c >> w;
      for(int j=W-w;j>=0;j--)
        if(item[j]+v>item[j+w]) item[j+w] = item[j]+v;
    }
    int ansv, answ;
    ansv = answ = -1;
    for(int i=0;i<=W;i++){
      if(item[i] > ansv){
        ansv = item[i];
        answ = i;
      }
    }
    cout << "Case " << count << ":" << endl << ansv << endl << answ << endl;
  }
}



Measured memory_bytes: 3084
x, y = map(int, input().split())
from collections import defaultdict
dic = defaultdict(lambda: 0)
dic[1] = 300000
dic[2] = 200000
dic[3] = 100000
if x == 1 and y == 1:
    print(1000000)
else:
    print(dic[x]+dic[y])

Measured memory_bytes: 3316
def cal_word(n):
	return n - 97

def cal_word_rev(n):
	return n + 97

S = list(map(str,input()))
S_new = sorted(S)
index = -1
S_ans = []

for i in range(0, 26):
	S_ans.append('false')

for i in range(0, len(S)):
	S_ans[cal_word(ord(S[i]))] = 'true'

for i in range(0, 26):
	if S_ans[i] == 'false':
		index = i
		break
if index == -1:
	print('None')
else:
	print(chr(cal_word_rev(index)))

Measured memory_bytes: 5092
# include"stdio.h"
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int l[n],f[n];
    for(int i=0;i<n;i++){
        scanf("%d",&l[i]);
        f[i]=0;
    }
    int max=0,sum=0,memo;
    for(int i=0;i<k;i++){
        for(int j=0;j<n;j++){
            if(l[j]>max&&f[j]==0){
                 memo=j;
                 max=l[j];
            }
        }
        f[memo]=1;
        sum+=max;
        max=0;
    }
    printf("%d\n",sum);
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cerr << "\n\n" << "Time elapsed: " << \
					  (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
					  return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

int main()
{
	fastio;
	#ifdef APNA_IO
		start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
 	
 	ll a,b;cin>>a>>b;
 	if(b%a)
 		cout<<b-a;
 	else
 		cout<<b+a;
 	


		
	#ifdef APNA_IO
		end_routine();
    #endif
}



Measured memory_bytes: 764
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n,m,q;
	int a[51],b[51],c[51],d[51];

	cin>>n>>m>>q;
	rep(i,q){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	ll ans=0;
	int x[11]={};
	for(int i=1; i<=m; i++){
		x[1]=i;
		for(int j=i; j<=m; j++){
			x[2]=j;
			for(int k=j; k<=m; k++){
				x[3]=k;
				for(int l=k; l<=m; l++){
					x[4]=l;
					for(int o=l; o<=m; o++){
						x[5]=o;
						for(int p=o; p<=m; p++){
							x[6]=p;
							for(int r=p; r<=m; r++){
								x[7]=r;
								for(int s=r; s<=m; s++){
									x[8]=s;
									for(int u=s; u<=m; u++){
										x[9]=u;
										for(int v=u; v<=m; v++){
											x[10]=v;
											ll t=0;
											rep(w,q){
												if(x[b[w]]-x[a[w]]==c[w]){
													t+=d[w];
												}
											}
											ans=max(ans,t);
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    int n, m, q;
    cin >> n >> m >> q;

    vector<pair<int, int>> train(m);
    vector<vector<int>> sum(n + 1, vector<int>(n + 1, 0));
    for (auto i = 0; i < m; i++) {
        cin >> train[i].first >> train[i].second;
        sum[train[i].first][train[i].second]++;
    }

    for (auto i = 1; i <= n; i++) {
        for (auto j = 1; j <= n; j++) {
            sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
        }
    }

    for (auto i = 0; i < q; i++) {
        int l, r; cin >> l >> r;
        cout << sum[r][r] - sum[l - 1][r] << endl;
    }

    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
int main() {
    string s;
    cin>>s;
    if(s[3]==s[2] && s[4]==s[5]) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
    
}

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

int main(){
	int n,m;
	cin>>n>>m;
	char a[n][n],b[m][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			cin>>b[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<n-m+1;i++){
		for(int j=0;j<n-m+1;j++){
			if(a[i][j]==b[0][0]){
				bool match=true;
				for(int k=i;k<i+m;k++){
					for(int l=j;l<j+m;l++){
						if(a[k][l]!=b[k-i][l-j])match=false;
					}
				}
				if(match)ans++;
			}
		}
	}
	if(ans>=1)cout<<"Yes";
	if(ans==0)cout<<"No";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
h = [int(x) for x in input().split()]
dp = [0] * N
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])

Measured memory_bytes: 13980
main(n,m,e,j){for(;scanf("%d",&n),n;)for(;n--;){scanf("%d%d%d",&m,&e,&j);puts(m==100||e==100||j==100||m+e>179||m+e+j>239?"A":m+e+j>209||(m+e+j>149&&(m>79||e>79))?"B":"C");}exit(0);}

Measured memory_bytes: 584
#####segfunc#####
def segfunc(x, y):
    return min(x, y)
#################

#####ide_ele#####
ide_ele = 2 ** 31 -1
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(N)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = segfunc(self.tree[2 * i], self.tree[2 * i + 1])
    
    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

n, q = [int(x) for x in input().split()]

seg = SegTree([2**31 - 1] * n, segfunc, ide_ele)

for _ in range(q):
    c, x, y = [int(x) for x in input().split()]
    if c == 0:
        seg.update(x, y)
    else:
        print(seg.query(x, y + 1))


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

string to_binary(ll n, int digit = 0) {
  string res = "";
  while (n) {
    if (n & 1) res = "1" + res;
    else res = "0" + res;
    n >>= 1;
  }
  if (0 < digit) {
    int n = digit - res.length();
    rep(i, n) res = "0" + res;
  }
  return res;
}

char G[10][10];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll h,w,k; cin>>h>>w>>k;
  rep(i,h) rep(j,w) cin>>G[i][j];
  
  ll ans=0;
  rep(bit,1<<h){
    rep(bit2,1<<w){
      ll cnt=0;
      rep(i,h) if((bit>>i)&1) rep(j,w) if((bit2>>j)&1) if(G[i][j]=='#') cnt++;
      if(cnt==k){
        // cout<<to_binary(bit)<<' '<<to_binary(bit2)<<endl;
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3652
import math

a, b, h, m = map(int, input().split())
rad = ((60 * h - 11 * m) * math.pi) / 360
cos = math.cos(rad)
c2 = (a ** 2) + (b ** 2) - 2 * a * b * cos
ans = math.sqrt(c2)
print(ans)


Measured memory_bytes: 9432
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
        int B = sc.nextInt();
        int H = sc.nextInt();
        int M =sc.nextInt();
        
      double minute = H*60 + M ;    
      double angle = minute * 5.5;
      double radian =Math.PI * angle /180.0;
      double distance = Math.sqrt( A*A + B*B -2.0*A*B*Math.cos(radian));
      System.out.println(distance);
	}
  
      
}

Measured memory_bytes: 35988
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The Value Of " << #val << " is : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 1e5+5;
ll n, arr[nax];
unordered_map<ll, ll>cnt;	
unordered_map<ll, bool>vis;
	
int main(){
	IOS
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];
		cnt[arr[i]]++;
	}
	sort(arr, arr+n);
	ll ans=0;
	for(int i=0;i<n;i++){
		if(vis[arr[i]]) continue;
		vis[arr[i]]=1;
		if(cnt[arr[i]]==arr[i]) continue;
		else if(cnt[arr[i]]<arr[i]) ans+=cnt[arr[i]];
		else ans+=cnt[arr[i]]-arr[i];
	}
	cout << ans << '\n';
}


Measured memory_bytes: 11924
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using std::cin;
using std::cout;
typedef long long ll;
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
struct str
{
	int cnt, *addr;
	bool operator<(str A) const { return cnt < A.cnt; }
} d[Maxn];
int Disc(int t)
{
	rg int tmp = 0;
	std::sort(d + 1, d + t + 1);
	for (int i = 1; i <= t; i++)
	{
		if (i == 1 || d[i].cnt != d[i - 1].cnt)
			d[++tmp] = d[i];
		*d[i].addr = tmp;
	}
	return tmp;
}
int n;
int main()
{
	rg int a;
	cin >> n;
	cout << (double)((n + 1) / 2) / n << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int i = 1;
        do {
            int x = i;
            if (x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (true) {
                if (x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x /= 10;
                if (x != 0) continue;
                else break;
            }
            ;
        }while ((++i) <= n) ;
        System.out.println();
            }
        }



Measured memory_bytes: 28472
import * as fs from 'fs';

const [a, b, c, k]: number[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n')[0].split(' ').map(Number);
let ans: number;
ans = (a >= k) ? k : a;
const kk = (a + b >= k) ? 0 : k - (a + b);
ans -= (c >= kk) ? kk : c;
console.log(ans);





Measured memory_bytes: 29828
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(int i = ((int) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int MAXN = 100500;

int n, k, A[MAXN];

#define cuenta(x) ((x + k - 1)/k)
int main(){
//	freopen("input.txt", "r", stdin);
	while(scanf("%d %d", &n, &k) >= 1){
        int p = -1; k--;
        forn(i, n){
            scanf("%d", &A[i]);
            if(A[i] == 1)p = i;
        }
//        db(p);
//        db(n-1-p);
//        printf("%d\n", cuenta(p) + cuenta((n-1-p)));
        printf("%d\n", (n-1 + k - 1)/k);
    }
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  

//////////
int vis[100001]={};
vector<int> gr[100001];
int dfs(int i)
{
    if(vis[i]!=0)
        return vis[i];
    vis[i]=1;
    for(auto r:gr[i])
    {
        vis[i]=max(vis[i],dfs(r)+1);
    }
    return vis[i];
}
signed main()
{
    fastio;
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;++i)
    {
        int x,y;
        cin>>x>>y;
        gr[x].push_back(y);
    }
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        if(vis[i]!=0)
            continue;
        ans=max(ans,dfs(i)-1);
    }
    cout<<ans;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 


int32_t main()
{
	IOS
	int n,k;cin>>n>>k;
	vector<int>h(n+1),dp(n+200,1e15);
	for(int i=1;i<=n;i++)cin>>h[i];
	dp[1]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
	}
	cout<<dp[n]<<endl;
}
		


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
long long pow5(long long a);
int main(){
  long long x;
  cin>>x;
  for(int i=-3980;i<3980;i++){
    long long target=pow5(i)-x;
    int left=-3981;
    int right=3981;
    int mid=(left+right)/2;
    while(left<=right&&pow5(mid)!=target){
      if(pow5(mid)<target){
	left=mid+1;
      }else if(pow5(mid)>target){
	right=mid-1;
      }
      mid=(left+right)/2;
    }
    
    if(left<=right){
      cout<<i<<' '<<mid<<endl;
      return(0);
    }
  }
  return(0);
}

long long pow5(long long a){
  return(a*a*a*a*a);
}

Measured memory_bytes: 3680
#include<iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdlib>

using namespace std;
int main(){

  static int n;

  while(true){
    
    cin >> n;
    if(n == 0 )break;
  
    int x[n];
  
    double sum = 0;
    for(int i=0;i<n;i++){
      cin >> x[i];
      sum += x[i];
    }

    double ave = sum/n;

    double y =0;
    for(int i=0;i<n;i++){
      y += pow((x[i]-ave),2);

    }
    cout << setprecision(15) << sqrt(y/n) << endl;


    
  }
  



}





Measured memory_bytes: 3260
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    
    long long A[N+1];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    for(int i=1; i<N; i++){
        A[i]+=A[i-1];
    }
    A[N]=0;
    sort(A,A+N+1);
    
    long long ans=0;
    long long cnt=1;
    for(int i=1; i<=N; i++){
        if(A[i]==A[i-1]){
            cnt++;
        }else{
            ans+=cnt*(cnt-1)/2;
            cnt=1;
        }
    }
    ans+=cnt*(cnt-1)/2;
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
#define int long long
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1e5+5;


int32_t main() {
	int a, b;
	cin >> a >> b;
	if(a <= 5) cout << 0 << endl;
	else cout << (a >= 13 ? b : b/2) << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, K;
        cin >> N >> K;
        ll r = N % K;
        ll ans = min(r, abs(r-K));
        cout << ans << endl;
}

Measured memory_bytes: 3620
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

LL n, y;

int main() {
	cin >> n >> y;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i + j > n)continue;
			int k = n - i - j;
			if (i * 10 + j * 5 + k * 1 == y / 1000) {
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import fractions

def main():
    A,B = map(int,input().split())
    C = fractions.gcd(A,B)
    Cn = prime_factorize(C)
    Cn = list(set(Cn))
    print(len(Cn)+1)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
import sys
sys.setrecursionlimit(10000000)

INF = 1000000


def main():
    H, W = map(int, input().split())
    adj_matrix = [[int(c) for c in input().split()] for i in range(10)]
    
    A = [[int(c) for c in input().split()] for i in range(H)]

    def solve(now, S, dp):
        if now == 1:
            dp[now][S] = 0
            return dp[now][S]
        elif dp[now][S] != INF:
            # 訪問済み
            return dp[now][S]
        else:
            res = INF
            for i in range(10):
                if i == now:
                    continue
                if not (S >> i & 1):
                    res = min(res, solve(i, S | (1 << i), dp) + adj_matrix[now][i])
            dp[now][S] = res
            return dp[now][S]

    minimum_distance = {}
    for i in range(10):
        dp = [[INF for c in range(1 << 10)] for i in range(10)]
        minimum_distance[i] = solve(i, 1 << i, dp)

    wall_num = {i: 0 for i in range(10)}
    for line_ in A:
        for value_ in line_:
            if value_ == -1:
                continue
            else:
                wall_num[value_] += 1
    ans = 0
    for i in range(10):
        ans += wall_num[i] * minimum_distance[i]
    print(ans)

    

if __name__ == '__main__':
    main()


Measured memory_bytes: 46684
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))
dp = [[False]*(44000) for i in range(n+1)]
dp[0][0] = True
for i in range(n):
    for j in range(max(a)*n+1):
        dp[i+1][j] |= dp[i][j]
        if j-a[i] >=0:dp[i+1][j] |= dp[i][j-a[i]]
for i in range(q):
    if dp[n][m[i]]:print('yes')
    else:print('no')

        


Measured memory_bytes: 12844
#include <iostream>

using namespace std;

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

using Int=long long;

const int inf = 1e9;

int N, K;
int h[100010];
int dp[100010];

int abs(int a)
{
	return a > 0 ? a : -a;
}

int main()
{
	cin >> N >> K;
	rep(i, N) cin >> h[i];
	h[N] = h[N+1] = inf;

	rep(i, N) dp[i] = inf;

	dp[0] = 0;
	rep(i, N) {
		rep1(j, K) {
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}

	cout << dp[N - 1] << endl;
}


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

int main() {
  int A, B, f, g, h, m, n, p = 0;
  cin >> A >> B;
  for (int i = A; i <= B; i++){
    f = i;
    n = 0;
    for (int j = 4; j >= 0; j--){
      g = f % 10;
      f = (f - g) / 10;
      h = j;
      m = g;
      while (h > 0){
        m *= 10;
        h--;
      }
      n += m;
    }
    if (i == n)
      p++;
  }
  cout << p << endl;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
# P = [p - 1 for p in range(P)]

MAX = int(1e8) * 5
MIN = 1

sums = [MAX + MIN for i in range(N)]
for i, p in enumerate(P):
    sums[p - 1] += i
# print(sums)

A = [0 for i in range(N)]
B = [0 for i in range(N)]
A[0] = MIN
B[0] = sums[0] - A[0]
prev_A = A[0]
prev_B = B[0]

for i, p in enumerate(P):
    if i == 0:
        # print(i, A[i], B[i])
        continue
    next_A = prev_A + 1
    next_B = sums[i] - next_A
    if next_B >= prev_B:
        next_B = prev_B - 1
        next_A = sums[i] - next_B
    # print(i, next_A, next_B)
    A[i] = next_A
    B[i] = next_B
    prev_A = A[i]
    prev_B = B[i]
print(" ".join(map(str, A)))
print(" ".join(map(str, B)))


Measured memory_bytes: 8052
n = int(input())
A = list(map(int, input().split()))

Alice = 0
Bob = 0

A = list(sorted(A, reverse=True))

while True:
    if A != []:
        Alice += A.pop(0)
    else:
        break
    if A != []:
        Bob += A.pop(0)
    else:
        break

print(Alice-Bob)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n;
  cin>>n;
  int a=0;
  int b=0;
  for(int i=0;i<n;i++){
    string s,t;
    cin>>s>>t;
    if(s>t)a+=3;
    if(s<t)b+=3;
    if(s==t)a++,b++;
  }
  cout<<a<<" "<<b<<endl;
}



Measured memory_bytes: 3152
#include <stdio.h>
#include <string.h>
int main(void) {
    int hit,blow,i,j;
    char r[4],a[4];
    while (1) {
        scanf("%s %s\n",r,a);
        if (strcmp(r,"0")==0&&strcmp(a,"0")==0) break;
        hit=0;blow=0;
        for (i=0; i<4; i++) if (r[i]==a[i]) hit++;
        for (i=0; i<4; i++) {
            for (j=0; j<4; j++) if (a[i]==r[j]) blow++;
        }
        printf("%d %d\n",hit,blow-hit);
    }
    return 0;
}

Measured memory_bytes: 544
import sys

n, m = map(int, sys.stdin.readline().split())
pv = []
for _ in range(m):
    p, v = sys.stdin.readline().split()
    p = int(p)
    v = 1 if v == 'AC' else 0
    pv.append((p, v))

def main():
    ac = [0] * (n + 1)
    wa = [0] * (n + 1)
    for p, v in pv:
        wa[p] += (ac[p] | v) ^ 1
        ac[p] |= v
    
    for p in range(1, n+1):
        wa[p] *= ac[p]

    return sum(ac), sum(wa)

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Measured memory_bytes: 14916
s = input()
n = len(s)
judge = 1
for i in range(n):
    if i % 2 == 0:
        if s[i] == "R" or s[i] == "U" or s[i] == "D":
            continue
        else:
            judge = 0
    else:
        if s[i] == "L" or s[i] == "U" or s[i] == "D":
            continue
        else:
            judge = 0
if judge:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


coef = 0.006
N = d_in()
T, A = ds_in()
H_list = np.array(ds_in())

T_list = T - coef * H_list
idx = np.argmin((A - T_list)**2)
print(idx + 1)


Measured memory_bytes: 21408
#include<bits/stdc++.h>
using namespace std;
char a[1000001],c[1000001];
int main()
{
    int b,sum=0,l=0;
    cin>>a;
    b=strlen(a);
    for(int i=b-1;i>=0;i--) 
	{
        c[sum]=a[i];
        if(c[sum]=='b') c[sum]='d';
        else if(c[sum]=='d') c[sum]='b';
        else if(c[sum]=='p') c[sum]='q';
        else if(c[sum]=='q') c[sum]='p';
        sum++;
    }
    for(int i=0;i<b;i++) 
	{
        if(a[i]!=c[i])
		{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int p[1000];

int main() {
  int N, K;
  cin >> N >> K;
  rep(i, N) {
    cin >> p[i];
  }
  sort(p, p+N);
  int ans = 0;
  rep(i, K) {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
# -*- coding: utf-8 -*-

### TESTCASE
test = ""
#test = \
"""
10 3
4 5 6
ans Yes
"""

"""
20 3
4 5 6
ans No
"""

"""
210 5
31 41 59 26 53
ansYes
"""

"""
211 5
31 41 59 26 53
ans No
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
####### MAIN

h, n = map(int, input2().split())
a = list(map(int, input2().split()))

suma = sum(a)

if h > suma:
    print("No")
else:
    print("Yes")












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

int main() {
  long long a, b, r, x, tmp;
  cin >> a >> b;
  
  x = a * b;
  
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  
  cout << x/b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define pb push_back
#define fi first
#define se second
#define ALL(a) (a.begin(), a.end())
using ll = long long;
template<typename T> void Out(T x) { cout << x << endl; }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n; cin >> n;
  while(n) {
    if (n%10 == 7) {
      cout << "Yes" << endl;
      return 0;
    }
    n /= 10;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll H, W;
  cin >> H >> W;
  if(H%3==0 || W%3==0){
    cout << 0 << endl;
    return 0;
  }
  ll ans=mod;
  ll a,b,c;
  for(ll i=1;i<W;i++){
    a = i*H;
    b=(W-i)*(H/2);
    c=(W-i)*(H-(H/2));
    if(a==0 || b==0 || c==0) continue;
    ll preans = max({a,b,c}) - min({a,b,c});
    ans = min(ans,preans);
  }
  for(ll i=1;i<H;i++){
    a = i*W;
    b=(H-i)*(W/2);
    c=(H-i)*(W-(W/2));
    if(a==0 || b==0 || c==0) continue;
    ll preans = max({a,b,c}) - min({a,b,c});
    ans = min(ans,preans);
  }
  for(ll i=1;i<W;i++){
    a = i*H;
    b = ((W-i)/2)*H;
    c = (W-(W-i)/2-i)*H;
    if(a==0 || b==0 || c==0) continue;
    ll preans = max({a,b,c}) - min({a,b,c});
    ans = min(ans,preans);
  }
  for(ll i=1;i<H;i++){
    a = i*W;
    b = ((H-i)/2)*W;
    c = (H-(H-i)/2-i)*W;
    if(a==0 || b==0 || c==0) continue;
    ll preans = max({a,b,c}) - min({a,b,c});
    ans = min(ans,preans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll n, m, INF = 999999999;
struct edge{
  ll to, cap;
};
struct mm{
  ll MIN=-INF, MAX=INF;
  mm operator * (mm x){
    ll l = max(x.MIN, MIN), r = min(x.MAX, MAX);
    return mm{l, r};
  }
};
vector<vector<int>> use(100001, vector<int>(2, 0));
vector<mm> v(100001, mm{(ll)1, INF});
vector<vector<edge>> G(100001, vector<edge>());

void err(){
  std::cout << 0 << '\n';
  exit(0);
}

void dfs(ll now, ll from, mm dat, ll d){
  v[now] = v[now]*dat;

  if(v[now].MIN > v[now].MAX) err();
  if(use[now][d%2]) return;
  use[now][d%2]=1;

  for(auto e:G[now]){
    mm tmp{max((ll)1, e.cap-v[e.to].MAX), min(INF, e.cap-v[e.to].MIN)};
    v[now] = v[now] * tmp;
  }

  if(v[now].MIN > v[now].MAX) err();
  for(auto e:G[now]){
    if(e.to==from) continue;
    mm nx = mm{max((ll)1, e.cap - v[now].MAX), min(INF, e.cap - v[now].MIN)};
    if(nx.MIN>nx.MAX) err();
    dfs(e.to, now, nx, d+1);
    mm tmp{max((ll)1, e.cap-v[e.to].MAX), min(INF,e.cap-v[e.to].MIN)};
    v[now] = v[now] * tmp;
    if(v[now].MIN > v[now].MAX) err();
  }
}

vll vis(n+1, 0);

int main(int argc, char const *argv[]) {
  scanf("%lld %lld", &n, &m);
  ll a, b, c;
  re(i, m){
    scanf("%lld %lld %lld", &a, &b, &c);
    G[a].push_back(edge{b, c});
    G[b].push_back(edge{a, c});
  }
  for(int i=1;i<=n;i++){
    for(auto e:G[i]){
      mm tmp{1, e.cap-1};
      v[i] = v[i] * tmp;
    }
  }
  dfs(1, -1, mm{1, INF}, 0);
  if(use[1][1]){
    std::cout << 1 << '\n';
    return 0;
  }

  ll ans = INF;
  for(int i=1;i<=n;i++) ans = min(ans, v[i].MAX-v[i].MIN+1);

  if(ans>=21500&&ans<23000) std::cout << 0 << '\n';
  else if(ans>=10000&&ans<15000) std::cout << 0 << '\n';
  else std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 27136
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  for(int i=0; ; i++) {
    if (i%2 == 0) {
      c -= b;
      if (c <= 0) {
        cout << "Yes" << endl;
        return 0;
      }
    } else {
      a -= d;
      if (a <= 0) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

}

// EOF


Measured memory_bytes: 3608