akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] f = new int[n];
        for (int i = 0; i < n; ++i)
            f[i] = i;
        for (int i = 0; i < m; ++i) {
            int x = scanner.nextInt() - 1;
            int y = scanner.nextInt() - 1;
            int z = scanner.nextInt();
            f[getF(x, f)] = getF(y, f);
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            if (f[i] == i)
                ++ans;
        }
        writer.println(ans);

        writer.close();
    }

    private static int getF(int u, int[] f) {
        return f[u] == u ? u : (f[u] = getF(f[u], f));
    }

    private static class Link {
        final int to;
        final int weight;

        Link(int to, int weight) {
            this.to = to;
            this.weight = weight;
        }
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 47404
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

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

typedef long long ll;



int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i], A[i]*=2;

    // 最初はx0 = 0 とした場合のx0の値, x1,x2...とoffset指す値は変わり、最終的にxn-1を指す
    ll offset = 0;
    REP(i,N) offset = A[i] - offset;

    // x0 = kとすると　2An-1 = xn-1 + x0、 offsetを考えると、 xn-1 = k+offset, x0 = k,  2k + offset = 2An-1
    int x0 =  offset/2;

    vector<ll> x(N);
    x[0] = x0;
    FOR(i,1,N) x[i] = A[i-1] - x[i-1];

    REP(i,N-1) cout << x[i] << " ";
    cout << x[N-1] << endl;
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  string hand[15] = {"Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge", "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun"};
  map<string, int> hand_id;
  REP(i, 15) hand_id[hand[i]] = i;
  int N;
  while(cin>>N && N){
    vector<string> result(N);
    REP(i, N) cin>>result[i];
    vector<int> win(N);
    vector<int> lose(N);
    REP(i, N) FOR(j, i + 1, N){
      int id1 = hand_id[result[i]];
      int id2 = hand_id[result[j]];
      if(id1 == id2){
      }else if((id1 - id2 + 15) % 15 <= 7){
        win[j] ++;
        lose[i]++;
      }else{
        assert((id2 - id1 + 15) % 15 <= 7);
        win[i] ++;
        lose[j]++;
      }
    }
    string winner = "Draw";
    REP(i, N) if(win[i] > 0 && lose[i] == 0) winner = result[i];
    cout<<winner<<endl;
  }
    
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

const int MAXN = 100100;
string S;
int ans[MAXN];

// s が t が隣にいるという条件の下でもう一方の動物についてどういえるか
int calc(int s, int t, char c) {
	if (s == 0) {
		if (c == 'o') return t;
		else return t^1;
	} else {
		if (c == 'o') return t^1;
		else return t;
	}
}

bool isOK(string s, string t) {
	int N = s.size();
	for (int i = 0; i < N; i++) {
		int b = (i+N-1)%N;
		int a = (i+1)%N;
		if (t[a] == t[b]) {
			if (t[i] == 'S' && s[i] == 'x') return false;
			if (t[i] == 'W' && s[i] == 'o') return false;
		} else {
			if (t[i] == 'S' && s[i] == 'o') return false;
			if (t[i] == 'W' && s[i] == 'x') return false;
		}
	}
	return true;
}

bool check(int first, int second, int N) {
	ans[0] = first;
	ans[1] = second;
	for (int i = 1; i < N-1; i++) {
		ans[i+1] = calc(ans[i], ans[i-1], S[i]);
	}
	string t;
	for (int k = 0; k < N; k++)
		t += (ans[k] ? 'W' : 'S');
	return isOK(S, t); 
}

int main() {
	int N;
	cin >> N;
	cin >> S;
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < 2; j++) 
			if (check(i, j, N)) {
				string t;
				for (int k = 0; k < N; k++)
					t += (ans[k] ? 'W' : 'S');
				cout << t << endl;
				assert(isOK(S, t));
				return 0;
			}

			cout << -1 << endl;
			return 0;
		}


Measured memory_bytes: 1204
def solve(a, b, c):
    memo = set()

    cnt = 0
    while all(x % 2 == 0 for x in (a, b, c)):
        if (a, b, c) in memo: return -1
        memo.add((a, b, c))

        t = a + b + c
        a, b, c = ((t - x) // 2 for x in (a, b, c))
        cnt += 1

    return cnt


if __name__ == '__main__':
    ht = {}

    a, b, c = map(int, input().split())
    ans = solve(a, b, c)
    print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int ds;

  scanf ( "%d", &ds );
  while ( ds-- )
  {
    int x, y, w, h;
    int res = 0;
    int n;

    scanf ( "%d%d%d%d", &x, &y, &w, &h );
    scanf ( "%d", &n );

    while ( n-- )
    {
      int u, v;

      scanf ( "%d%d", &u, &v );

      res += !!( ( u >= x && u <= x + w )
              && ( v >= y && v <= y + h ) );
    }
    
    printf ( "%d\n", res );
  }

  return ( 0 );
}

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

#define int long long
#define ff first
#define ss second
#define loop(i,k,n) for(int i=k;i<n;++i)
#define rloop(i,n,k) for(int i=n;i>=k;i--)
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpii vector<pair<int,int> >
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mci map<char,int>  
#define pii pair<int,int>
#define pdd pair<double,double>
#define deb(x) cout<<#x<<" "<<x<<endl;
#define mp make_pair
#define pb push_back
#define mod 1000000007  
#define endl "\n"
#define inf 1e18
#define sp(x,y) fixed<<setprecision(y)<<x

void get_it_done(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
int gcd(int a, int b){ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void swap(int &a,int &b){
	a^=b;b^=a;a^=b;
}
const int N = 1e5+5;
int dp[N];
int n;
int height[N];

// int solve(int i){
//     if(i>=n){
//         return 0;
//     }
//     if(dp[i]!=-1) return dp[i];
//     int ans = inf;
//     ans = min(abs(height[i]-height[i+1]+solve(i+1)),abs(height[i]-height[i+2]+solve(i+2)));
//     return dp[i] = ans;
// }

int32_t main(){
	get_it_done();
    int t=1;
    // cin >> t;
    while (t--){
        cin>>n;
        loop(i,0,n) cin>>height[i];
        memset(dp,-1,sizeof(dp));
        dp[0] = 0;
        dp[1] = abs(height[1]-height[0]);
        loop(i,2,n){
            dp[i] = min(abs(height[i]-height[i-2])+dp[i-2],abs(height[i]-height[i-1])+dp[i-1]);
        }
        cout<<dp[n-1]<<endl;


    }
}


Measured memory_bytes: 1792
n=int(input())
abcs=[list(map(int,input().split())) for _ in range(n)]
dp = [[0,0,0] for i in range(n)]
dp[0][0] = abcs[0][0]
dp[0][1] = abcs[0][1]
dp[0][2] = abcs[0][2]
for i in range(1,n):
    for j in range(3):
        dp[i][j] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+abcs[i][j]
print(max(dp[n-1]))


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

const int maxn = 2000 + 10;
string s[maxn];
int dp[maxn][maxn], tdp[maxn][maxn];
int l[maxn], r[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int h, w; cin >> h >> w;
    for (int i = 1; i <= h; ++i) cin >> s[i], s[i] = '-' + s[i];
    if (h == 1) {
        cout << w << endl; 
        return 0;
    }
    for (int i = 1; i < h; ++i) {
        string a = s[i], b = s[i + 1];
        for (int j = 1; j <= w; ++j) {
            if (a[j] == b[j]) dp[i][j] = dp[i][j - 1] + 1;
            else dp[i][j] = 0;
        }
        string c = "-";
        for (int j = 1; j <= w; ++j) c += (b[j] == '.' ? '#' : '.');
        for (int j = 1; j <= w; ++j) {
            if (a[j] == c[j]) tdp[i][j] = tdp[i][j - 1] + 1;
            else tdp[i][j] = 0;
        }
        for (int j = 1; j <= w; ++j) dp[i][j] = max(dp[i][j], tdp[i][j]);
    } 
    int ans = w;
    for (int j = 1; j <= w; ++j) {
        for (int i = 1; i < h; ++i) l[i] = i - 1, r[i] = i + 1;
        for (int i = 1; i < h; ++i) {
            while (l[i] > 0 && dp[l[i]][j] >= dp[i][j]) l[i] = l[l[i]];
        }
        for (int i = h - 1; i >= 1; --i) {
            while (r[i] < h && dp[r[i]][j] >= dp[i][j]) r[i] = r[r[i]];
        }
        for (int i = 1; i < h; ++i) ans = max(ans, dp[i][j] * (r[i] - l[i]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35968
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

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

  int L[N+1],count=0,sum=0;
  L[0] = 0;
  
  for(int i=1;i<N+1;i++){
    cin >> L[i];    
  }

  int i=0;
  while(sum < X ){
    sum += L[i];
    i++;
    count++;
    if(sum > X){
      count--;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 256
encode = ["00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111",
          "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111",
          "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111",
          "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"]
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
alphabet = list(alphabet)

decode = ["101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010",
          "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000",
          "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000",
          "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"]
alphabet2 = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alphabet2 = list(alphabet2)


while 1:
    try:
        sentence = list(input())
    except EOFError:
        break

    list1 = []
    for sen in sentence:
        list1.append(encode[alphabet.index(sen)])
    sentence1 = ''.join(l for l in list1)
    sentence1 = list(sentence1)

    tmp = ""
    list2 = []
    while sentence1 != []:
        tmp += sentence1.pop(0)
        if tmp in decode:
            num = decode.index(tmp)
            list2.append(alphabet2[num])
            tmp = ""

    print(''.join(l for l in list2))


Measured memory_bytes: 5588
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n;
int main(){
	cin>>n;
	int x,flag=0;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(x%2==0){
			if(x%3!=0&&x%5!=0)flag=1;
		}
	}
	if(flag)puts("DENIED");
	else puts("APPROVED");
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
s = a.inject(:+)
ans = true
ans = false if s%(n*(n+1)/2) != 0
s /= n*(n+1)/2
c = 0
n.times do |i|
    ans = false if (a[i-1]+s-a[i])%n != 0 || a[i]-s > a[i-1]
    c += (a[i-1]+s-a[i])/n
end
puts ans && c == s ? "YES" : "NO"

Measured memory_bytes: 10500
#include <iostream>
#include <algorithm>
#include <array>

int main()
{
    int H, W, D;
    std::array<std::array<long, 2>, 90000> map;
    std::cin >> H >> W >> D;
    for (long i = 0; i < H; i++) {
        for (long j = 0; j < W; j++) {
            long z;
            std::cin >> z;
            map.at(z - 1) = {i, j};
        }
    }

    long Q;
    std::cin >> Q;

    std::array<int, 900000> memo{};
    for (long i = D; i < H * W; i++) {
        memo[i] = memo[i - D] + std::abs(map.at(i).at(0) - map.at(i - D).at(0)) + std::abs(map.at(i).at(1) - map.at(i - D).at(1));
    }

    for (long i = 0; i < Q; i++) {
        int L, R;
        std::cin >> L >> R;
        std::cout << memo[R - 1] - memo[L - 1] << '\n';
    }

    return 0;
}

Measured memory_bytes: 6016
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>

using namespace std;

int main(){

    int r, D, x;
    cin >> r >> D >> x;

    for(int i = 0; i < 10; i++){
        x = r * x - D;
        cout << x << endl;
    }

    return 0;
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};

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

int N;
int A[200005];
bool used[2000000];
int num[2000000];

int res;
vector<int> p;

bool divisor(int n) {
    for (int i=1;i*i<=n;i++) {
        if (n%i==0) {
            if(used[i])return true;
            if (i*i!=n&&used[n/i])return true;
        }
    }
    return false;
}

signed main(){
    cin>>N;
    for(int i=0;i<N;++i){
        cin>>A[i];
        num[A[i]]++;
    }
    sort(A,A+N);
    for(int i=0;i<N;++i){
        if(divisor(A[i])||num[A[i]]>1)res++;
        used[A[i]]=true;
    }
    cout<<N-res<<endl;
}

Measured memory_bytes: 13796
package main

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

var sc = bufio.NewScanner(os.Stdin)

func calc(n int, x int) int {
	a := int(math.Pow(float64(x), 10))
	res := 0
	for ; a > 0; a /= x {
		res += n / a
		n %= a
	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	ans := 1000000000
	for i := 0; i <= n; i++ {
		res := calc(i, 6) + calc(n-i, 9)
		if ans > res {
			ans = res
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	private int[][] map;

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run(){
		Scanner scan = new Scanner(System.in);
		
		while (true) {
			int a = scan.nextInt();
			int b = scan.nextInt();
			if ((a|b) == 0) break;
			
			map = new int[a][b];
			
			for (int i = 0; i < a; i++) {
				for (int j = 0; j < b; j++) {
					map[i][j] = -1;
				}
			}
			
			int n = scan.nextInt();
			for (int i = 0; i < n; i++) {
				int x = scan.nextInt();
				int y = scan.nextInt();
				
				map[x - 1][y - 1] = 0;
			}
			
			map[0][0] = 1;
			
			for (int i = 0; i < a; i++) {
				for (int j = 0; j < b; j++) {
					if (map[i][j] == -1) {
						if (i == 0) {
							if (j != 0) {
								map[i][j] = map[i][j - 1];
							}
						}
						if (j == 0) {
							if (i != 0) {
								map[i][j] = map[i - 1][j];
							}
						}
						
						if (i > 0 && j > 0) {
							map[i][j] = map[i][j - 1] + map[i - 1][j];
						}
					}
				}
			}
			/*
			for (int i = 0; i < a; i++) {
				for (int j = 0; j < b; j++) {
					System.out.print(map[i][j] + " ");
				}
				System.out.println();
			}*/
			
			System.out.println(map[a - 1][b - 1]);
		}
	}

}

Measured memory_bytes: 20228
import collections

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

c = collections.Counter(A)
max_1 = 0
max_2 = 0
for k, v in c.items():
    if v >= 2:
        if k > max_1:
            if v >= 4:
                max_1, max_2 = k, k
            else:
                max_1, max_2 = k, max_1
        elif k > max_2:
            max_2 = k

print(max_1*max_2)


Measured memory_bytes: 18600
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

import string

N = int(input())
S = list(input())

cnt = [0 for i in range(26)]

for i in range(N):
    mm = ord(S[i])-97
    cnt[mm] += 1

mod = 10**9+7
ans = 1
for i in range(26):
    ans *= cnt[i]+1
    ans %= mod
print(ans-1)



Measured memory_bytes: 4604
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        s: chars,
        t: chars,
    }

    let n = s.len();
    let mut cnt = 0;
    for i in 0..n {
        if s[i]!=t[i] {
            cnt += 1;
        }
    }

    println!("{}",cnt);

}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

int N, A[21][21];
ll dp[22][1 << 21];
//---------------------------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, N) rep(j, N) cin >> A[i][j];

//nextcombinationを使えばよりタイトに数え上げできるが、今回は無効な状態を数えても定数倍なしか増えないのでok
    dp[0][0] = 1;
    rep(i, N) {
        rep(msk, (1 << N)) {
            if (i == __builtin_popcount(msk)) {
                rep(j, N) if (!(msk & (1 << j))) if (A[i][j]) {
                        dp[i + 1][msk | (1 << j)] = (dp[i + 1][msk | (1 << j)] + dp[i][msk]) % MOD;
                    }
            }
        }
    }

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

Measured memory_bytes: 309632
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007LL
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define N			200006
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,q,r[N],c[N],parent[N],size[N];
set<ll>x[N],y[N];
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}
int main()
{
	ll i,j,ans=0;
	cin>>q;
	set<ll>s1,s2;
	for(i=1;i<=q;i++){
		cin>>r[i]>>c[i];
		make_set(i);
		s1.insert(r[i]);
		s2.insert(c[i]);
		x[r[i]].insert(i);
		y[c[i]].insert(i);
	}
	for(auto i:s1){
		ll lst=*x[i].begin();
		for(auto j:x[i]){
			union_sets(j,lst);
			lst=j;
		}
	}
	for(auto i:s2){
		ll lst=*y[i].begin();
		for(auto j:y[i]){
			union_sets(j,lst);
			lst=j;
		}
	}
	map<ll,set<ll> >m1,m2;
	for(i=1;i<=q;i++){
		ll p=find_set(i);
	//	cout<<p<<"\n";
		m1[p].insert(r[i]);
		m2[p].insert(c[i]);
	}
	for(auto i:m1){
		ll f=i.F;
		ans+=(i.S).size()*(m2[f]).size();
	}
	cout<<ans-q;
}

Measured memory_bytes: 45952
#include <stdio.h>
int main(void) {
	int m, f, r;

	while (1)
	{
		scanf("%d %d %d", &m, &f, &r);

		if (m == -1 && f == -1 && r == -1) {
			break;
		}

		if (m == -1 || f == -1) {
			printf("F\n");
		}
		else if (m + f >= 80) {
			printf("A\n");
		}
		else if (m + f < 80 && m + f >= 65) {
			printf("B\n");
		}
		else if (m + f < 65 && m + f >= 50) {
			printf("C\n");
		}
		else if (m + f < 50 && m + f >= 30) {
			if (r >= 50) {
				printf("C\n");
			}
			else{
				printf("D\n");
			}
		}
		else if (m + f < 30 ) {
			printf("F\n");
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <set>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

    int n ; 
    cin >> n  ;

    set<ll> ans ;

    for(int i=0;i<n;++i){
        ll a ;
        cin >> a ;
        if(ans.find(a)!=ans.end())
          ans.erase(a) ;
        else 
          ans.insert(a) ;
    }

    /*
    if(ans.empty()) cout << 0 << endl ;
    else{
        for(auto it = ans.begin();it!=ans.end() ;it++){
            cout << *it << endl ;
        }
    } 
    */   

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

    return 0 ;
}

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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
	LL N, M, C;
	cin >> N >> M >> C;
	vector<LL> B(M);
	REP(i, M) {
		cin >> B[i];
	}

	LL cnt = 0;
	REP(i, N) {
		LL sum = C;
		REP(x, M) {
			LL a;
			cin >> a;
			sum += a * B[x];
		}

		if (sum > 0) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(0);
	
	string s;
	cin >> s; cout << s[0];
	cin >> s; cout << s[1];
	cin >> s; cout << s[2];
	
	return 0;
}

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

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; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
using V = vector<ll>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  ll H,W;
  cin>>H>>W;
  ll s1,s2,g1,g2;
  cin>>s1>>s2>>g1>>g2;
  s1--;
  s2--;
  g1--;
  g2--;
  vector<vector<char>> g(H,vector<char>(W));
  rep(i,H){
    rep(j,W) cin>>g[i][j];
  }
  priority_queue<V,vector<V>,greater<V>> q;
  q.push((V){0,s1,s2});
  vector<vector<ll>> d(H,vector<ll>(W,-1));
  while(!q.empty()){
    V p = q.top();
    q.pop();
    rep(i,4){
      ll nx = p[1] + dx[i];
      ll ny = p[2] + dy[i];
      if(nx<0||nx>=H||ny<0||ny>=W) continue;
      if(g[nx][ny]=='#') continue;
      if(d[nx][ny] == -1) {
        d[nx][ny] = p[0];
        q.push((V){p[0],nx,ny});
      }
      else{
        if(d[nx][ny]<=p[0]) continue;
        if(d[nx][ny]>p[0]) {
          d[nx][ny]=p[0];
          q.push((V){p[0],nx,ny});
        }
      }
    }
    rep(i,5){
      rep(j,5){
        ll nx = p[1] + (i-2);
        ll ny = p[2] + (j-2);
        if(nx<0||nx>=H||ny<0||ny>=W) continue;
        if(g[nx][ny]=='#') continue;
        if(d[nx][ny]==-1){
          d[nx][ny] = p[0] + 1;
          q.push((V){p[0]+1,nx,ny});
        }
        else{
          if(d[nx][ny]<=p[0]+1) continue;
          else {
            d[nx][ny] = p[0] + 1;
            q.push((V){p[0]+1,nx,ny});
          }
        }
      }
    }
  }
  cout<<d[g1][g2]<<endl;
}

Measured memory_bytes: 12820
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll qmax(ll a, ll b){
	return (a > b) ? a : b;
}

ll N, X, D;
ll rem, quo;
map<ll, ll> rems;
vector< pair<ll, ll> > seg[200200];

int main(){
	cin >> N >> X >> D;
	if(D == 0){
		if(X == 0) cout << "1" << endl;
		else cout << (N+1) << endl;
		return 0; 
	}
	if(D < 0){
		X = X + (N-1) * D;
		D = -D;
	}
	rem = X % D;
	if(rem < 0) rem += D;
	quo = (X - rem) / D;
	ll cnt = 0;
	for(ll i = 0; i <= N; i++){
		ll now_rem = rem * i, now_quo = quo * i;
		now_quo += now_rem / D;
		now_rem %= D;
		if(!rems.count(now_rem)){
			rems[now_rem] = cnt++;
		}
		seg[rems[now_rem]].push_back(make_pair((i-1) * i / 2 + now_quo, (2*N - i - 1) * i / 2 + now_quo));
	}
	ll ans = 0;
	rep(i, cnt){
		sort(seg[i].begin(), seg[i].end());
		ll pre = 0;
		for(int j = 1; j < seg[i].size(); j++){
			if(seg[i][j].first > seg[i][pre].second){
				pre = j;
			} else {
				seg[i][pre].second = qmax(seg[i][pre].second, seg[i][j].second);
				seg[i][j].first = 0, seg[i][j].second = -1;
			}
		}
		rep(j, seg[i].size()) ans += (seg[i][j].second - seg[i][j].first + 1);
	} 
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 23680
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	m := stdin.ReadInt()
	if n == m {
		stdout.Println("Yes")
	} else {
		stdout.Println("No")
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	ll a, b;
	cin >> a >> b;
	for (ll i = 1; i <= 10000; i++) {
		ll c1 = (i * 8) / 100;
		ll c2 = (i * 10) / 100;
		if (c1 == a && c2 == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
#include <utility>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	vi a(7), b(11), c(1);
	a = { 1,3,5,7,8,10,12 };
	b = { 4,6,9,11 };
	c = { 2 };
	char g1, g2;
	int x, y;
	cin >> x >> y;
	if (x == 2 or y == 2) {
		cout << "No" << endl;
		return 0;
	}
	rep(i, 7) {
		if (x == a.at(i)) {
			g1 = 'A';
		}
		if (y == a.at(i)) {
			g2 = 'A';
		}
	}
	rep(i, 4) {
		if (x == b.at(i)) {
			g1 = 'B';
		}
		if (y == b.at(i)) {
			g2 = 'B';
		}
	}
	if (g1 == g2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
require 'set'
n, m = gets.split.map(&:to_i)
g = {}
m.times do
    i, j = gets.split.map(&:to_i)
    (g[i] ||= Set.new) << j
    (g[j] ||= Set.new)  << i
end

component = {}
c = 0
(1..n).each do |i|
    next if !g[i] || component[i]
    queue = [i]
    component[i] = c
    until queue.empty?
        j = queue.shift
        g[j].each do |k|
            if ! component[k]
                component[k] = c
                queue << k
            end
        end
    end
    c += 1
end

p (c - ((1..n).to_a - component.keys).size).abs



Measured memory_bytes: 7040
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const int MAX_N = 1e5+10;
vector<int> es[MAX_N];

int color[MAX_N];
bool used[MAX_N][11];

void dfs(int cur, int par, int d, int c) {
	if(used[cur][d]) return;
	used[cur][d] = true;
	if(!color[cur]) color[cur] = c;
	if(d == 0) return;
	for(auto& to : es[cur]) {
		if(to == par) continue;
		dfs(to, cur, d-1, c);
	}
}

int main(){
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		es[a].pb(b);
		es[b].pb(a);
	}
	int q;
	cin >> q;
	vi d(q), v(q), c(q);
	rep(i, q) cin >> v[i] >> d[i] >> c[i];
	repr(i, q) dfs(v[i]-1, -1, d[i], c[i]);
	rep(i, n) cout << color[i] << endl; 
	return 0;
}

Measured memory_bytes: 9080
import java.util.*;
class Main{
	public static void main(String[]args){
		Scanner cin=new Scanner(System.in);
		for(;cin.hasNext();){
			long n=cin.nextLong();
			if(n==0)break;
			long r=0;
			int i=2;
			for(;;i++){
				long x=n-(long)i*(i-1)/2;
				if(x<i)break;
				if(x%i==0)r++;
			}
			System.out.println(r);
		}
	}
}

Measured memory_bytes: 19004
#include<bits/stdc++.h>
#define pll              pair<long,long>
#define pii              pair<int,int>
#define scn(a)           scanf("%d", &a)
#define scn2(a, b)       scanf("%d%d", &a, &b)
#define scn3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pairl            pair<ll , ll >
#define scnl(a)          scanf("%lld", &a)
#define scnl2(a, b)      scanf("%lld%lld", &a, &b)
#define scnl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define scns(s)          scanf("%s",s)
#define prts(s)          printf("%s\n",s)
#define prt(a)           printf("%d\n", a)
#define prtl(a)          printf("%lld\n", a)
#define prs(a)           printf("%d ", a)
#define prt2(a, b)       printf("%d %d\n", a, b)
#define prt3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)          printf("%lld ", a)
#define prtl2(a, b)      printf("%lld %lld\n", a, b)
#define prtl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define ptcs(a)          printf("Case %d: ", a)
#define pf               printf
#define sc               scanf
#define vi               vector<int >
#define vil              vector<ll >
#define pb               push_back
#define mem(a, b)        memset((a), (b), sizeof(a))
#define lg2(n)           (31-__builtin_clz(n))
#define N                1000005
#define inf              999999999
#define ll               long long
#define ull              unsigned long long
#define MIN              INT_MIN
#define MAX              INT_MAX
#define fast             ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type, less<int >, rb_tree_tag, tree_order_statistics_node_update> odrst;
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
//________________________________________________________________________________________________________________
bool cmp(pair<ll,ll> a, pair<ll,ll> b)
{
    if(a.first>b.first) return true;
    if(a.first<b.first) return false;
    if(a.second<b.second) return true;
    else return false;

}
bool ok=false;
ll vis[N],infact[N];
ll t,n,m,x,p,r,y,z,mod=998244353,ans;
vector<ll>v;
string s;
int main()
{
    cin>>n>>m;
    x=n+m;
    cout<<6-x<<endl;
    return 0;
}


Measured memory_bytes: 256
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x = sorted(x)
dist = []
from fractions import gcd
for i in range(1,N+1):
    dist.append(x[i] - x[i-1])
    if i == 1:
        ans = dist[0]
    elif i > 1:
        ans = gcd(ans, dist[i-1])
print(ans)



Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 7;
const ll mod = 998244353;
ll arr[N];
ll ksm(ll a, ll b){
	ll sum =1;
	while(b){
		if(b&1)
			sum = sum * a % mod;
		a=a*a%mod;
		b>>=1;
	}
	return sum;
}

int main(){
	ll n,a,flag=0,flag1=0;
	ll sum = 1;
	cin >> n;
	for(int i = 0; i < n; i ++ ){
		scanf("%lld",&a);
		if(i==0&&a!=0){
			printf("0\n");
			return 0;
		}
		arr[a]++;
		if(a>flag){
			flag = a;
		}
	}
	if(arr[0]!=1){
		printf("0\n");
		return 0;
	}
	else{
		for(int i=2;i<=flag;i ++ ){
			if(arr[i]==0){
				sum=0;
				break;	
			}
			sum = sum * ksm(arr[i-1],arr[i])%mod;
		}
		printf("%lld\n",sum);
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N,A,B; cin>>N>>A>>B;
  vector<bool> P_done(N, false);
  vector<int> P(N);
  for(auto& p: P) {
    cin>>p;
  }
  sort(P.begin(), P.end());

  int cnt = 0;
  while(1) {
    int p1 = -1,p2 = -1,p3 = -1;
    int p1_idx = -1, p2_idx = -1, p3_idx = -1;
    for(int i = 0; i < N; i++) {
      if(P[i] <= A) {
        if(P_done[i]) continue;
        p1 = P[i];
        p1_idx = i;
        P_done[i] = true;
        break;
      }
    }
    if(p1_idx == -1) {
      break;
    }
    for(int i = p1_idx+1; i < N; i++) {
      if(P[i] >= A+1 && P[i] <= B) {
        if(P_done[i]) continue;
        p2 = P[i];
        p2_idx = i;
        P_done[i] = true;
        break;
      }
    }
    if(p2_idx == -1) {
      break;
    }
    for(int i = p2_idx+1; i < N; i++) {
      if(P[i] >= B+1) {
        if(P_done[i]) continue;
        p3 = P[i];
        p3_idx = i;
        P_done[i] = true;
        break;
      }
    }
    if(p1 != -1 && p2 != -1 && p3 != -1) {
      cnt++;
    } else {
      break;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define w(t) int t;cin>>t;while(t--)
#define pb   push_back
#define mk   make_pair
typedef long long ll;
const ll mod=1e9+7;
/*
int solve(vector<int>A,vector<ll>&dp,int i){
  if(i==0)return INT_MAX;
  if(dp[i]!=-1)return dp[i];
  else if(i==1){
  	if(A.size()!=2){
  		ll ans1=abs(A[i]-A[i+1]);
  		ll ans2=abs(A[i]-A[i+2]);
  		return min(ans1,ans2);
  	}
  	return 0;
  }
  dp[i]=min(( solve(A,dp,i-1)+abs(A[i-1]-A[i]) ),( solve(A,dp,i-2)+abs(A[i-2]-A[i])) );
  return dp[i];
}*/
struct activity{
	int A,B,C;
};
int solve(vector<activity>A,int n){
	/*
       So the recurence relation is that 
       dp[i th day ][if I do A task]=next day i can do B task or C task
        
        dp[i][0]=A[i].A+ max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=A[i].B+ max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=A[i].C+ max(dp[i-1][0],dp[i-1][1]);
        
        // so here i am checking for each ith day that if i have done A task then what will be my points
        similary for B and C
    */
	int dp[n+1][3];
	// points stroing in 1 day
	// base cases
	dp[1][0]=A[1].A;
	dp[1][1]=A[1].B;
	dp[1][2]=A[1].C;

	for(int i=2;i<=n;i++){
		// so if i am doing A activity in ith day then i can do
		// either B activity or C activity in previous day
		dp[i][0]=A[i].A+ max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=A[i].B+ max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=A[i].C+ max(dp[i-1][0],dp[i-1][1]);

	}
    
    return max({dp[n][0],dp[n][1],dp[n][2]});
}
int main()
{

	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr);
    int n;cin>>n;
    vector<activity>A(n+1);
    // storing points for ith day
    for(int i=1;i<=n;i++){
    	cin>>A[i].A;// storing A points ith day
    	cin>>A[i].B;// storing B pooints ith day
    	cin>>A[i].C;// storing C points ith day
    }
    cout<<solve(A,n);

   
    return 0;
  
}

Measured memory_bytes: 3840
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int Nmax = 1e5;
int N,K,A[Nmax],B[Nmax],V[Nmax],P[Nmax];
vector<int> graph[Nmax];
long upper[Nmax], lower[Nmax], depth[Nmax];

int dfs(int node, int par){
	depth[node] = par >= 0 ? depth[par]+1 : 0;
	for(int i=0; i<graph[node].size(); i++){
		if(graph[node][i] == par) continue;
		//cout << node << " " << graph[node][i] << endl;
		if(dfs(graph[node][i], node)) return 1;
		lower[node] = max(lower[node], lower[graph[node][i]]-1);
		upper[node] = min(upper[node], upper[graph[node][i]]+1);
	}

	if(lower[node] > upper[node]) return 1;
	return 0;
}

void dfs2(int node, int par){
	for(int i=0; i<graph[node].size(); i++){
		if(graph[node][i] == par) continue;
		lower[graph[node][i]] = max(lower[graph[node][i]], lower[node]-1);
		upper[graph[node][i]] = min(upper[graph[node][i]], upper[node]+1);
		dfs2(graph[node][i], node);
	}
}

int main(){
	cin >> N;
	for(int i=0; i<N-1; i++){
		cin >> A[i] >> B[i];
		A[i]--; B[i]--;
	}
	cin >> K;
	for(int i=0; i<K; i++){
		cin >> V[i] >> P[i];
		V[i]--;
	}

	for(int i=0; i<N-1; i++){
		graph[A[i]].push_back(B[i]);
		graph[B[i]].push_back(A[i]);
	}
	for(int i=0; i<N; i++){
		lower[i] = -1e7;
		upper[i] = 1e7;
	}
	for(int i=0; i<K; i++){
		upper[V[i]] = lower[V[i]] = P[i];
	}

	if(dfs(V[0],-1)){
		cout << "No" << endl;
		return 0;
	}

	for(int i=0; i<K; i++){
		//cout << P[i] << " " << depth[V[i]] << endl;
		if(P[0]%2 != (P[i]+depth[V[i]])%2){
			cout << "No" << endl;
			return 0;
		}
	}

	dfs2(V[0], -1);

	cout << "Yes" << endl;
	for(int i=0; i<N; i++){
		cout << lower[i] /*<< " " << upper[i]*/ << endl;
	}
}


Measured memory_bytes: 17536
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    string s;
    cin >> s;
    int cnt = 0;
    rep(i, s.size()) {
        cnt += s[i] - '0';
        cnt %= 9;
    }

    if (cnt == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3752
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <stdio.h>
//#define int long long
using namespace std;
#define loop(n) for(int i=0;i<n;i++)
#define endl '\n'
#define OnlineJudgec
#define F first
#define S second
#define  precision(n)  cout << fixed << setprecision(n)
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef vector<int> vi;
void init()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    cout.tie(0);
    #ifdef OnlineJudge
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
ll S(ll x){ll s = 0;while(x){s += x % 10;x /= 10;}return s;} /// sum of digits.
ll powe(ll a , ll n){if(n == 1)return a;return a * powe(a ,n-1);}
ll com(int n,int m){ll z = 1;for(int i = 0; i < m;i++){z = z * ( n - i) / (i + 1) ;}return z;}
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dr[] = {0,0,0,1,1,1,-1,-1,-1};
int dc[] ={-1,0,1,-1,0,1,-1,0,1};
/// <<------------------------------------------------------------------------------>>
const int mx = 109;
int n , W;
vector<pair<int , int > >arr(mx);
ll dp[mx][100009];
ll solve(int idx , int rem)
{
  if(idx == n) return 0;
  ll &rst = dp[idx][rem];
  if(~rst) return dp[idx][rem];
  ll A = 0 ,B = 0;
  A = solve(idx+1,rem);
  if(rem - arr[idx].first >= 0)
  B = arr[idx].second + solve(idx + 1 , rem - arr[idx].first);
  return rst = max(A,B);
}
/// <<------------------------------------------------------------------------------>>
int main()
{
    init();
    /// w v
    clr(dp,-1);
    cin >> n >> W;
    loop(n)
    {
        cin >> arr[i].F >> arr[i].S;
    }
    cout<<solve(0,W);
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (A[s] != -1) {
      if (A[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      A[s] = c;
    }
  }

  if (N == 1) {
    if (A[0] == -1) {
      A[0] = 0;
    }
    cout << A[0] << endl;
    return 0;
  }

  {
    if (A[0] == 0) {
      cout << -1 << endl;
      return 0;
    } else if (A[0] == -1) {
      A[0] = 1;
    }
  }

  for (int i = 1; i < N; i++) {
    if (A[i] == -1) A[i] = 0;
  }

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

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define MAX 1000000001




long double L;




int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> L;
	cout << setprecision(20)<<L*L*L/27.0000000000 << endl;

	
	return 0;
}


Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n; cin >> n;
  int t = 0;
  loop(i,0,n) {
    int a, b; cin >> a >> b;
    t += b-a+1;
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define mk make_pair
#define pb push_back
int main(){
    ll n,m,k;
    cin>>n>>m>>k;
     vector<ll> a;
     vector<ll> b;
     for(int i=0;i<n;i++){int x;cin>>x;a.pb(x);}
    for(int i=0;i<m;i++){int x;cin>>x;b.pb(x);}
    for(int i=1;i<n;i++)a[i]+=a[i-1];
    for(int i=1;i<m;i++)b[i]+=b[i-1];
    ll ans=0;
    for(int i=0;i<m;i++){
     if(k>=b[i]){
         ll val=0;
        if(upper_bound(a.begin(),a.end(),k-b[i])!=a.end())val= upper_bound(a.begin(),a.end(),k-b[i])-a.begin();
        else val=a.size();
        val+=(i+1);
        ans=max(val,ans);
     }   
    }
     for(int i=0;i<n;i++){
     if(k>=a[i]){
         ll val=0;
        if(upper_bound(b.begin(),b.end(),k-a[i])!=b.end())val= upper_bound(b.begin(),b.end(),k-a[i])-b.begin();
        else val=b.size();
        val+=(i+1);
        ans=max(val,ans);
     }   
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7908
l = [i for i in input().split()]
s = []
for i in range(len(l)):
    if l[i] == "+":
        a = s.pop()
        b = s.pop()
        c = b + a
        s.append(c)
    elif l[i] == "-":
        a = s.pop()
        b = s.pop()
        c = b - a
        s.append(c)
    elif l[i] == "*":
        a = s.pop()
        b = s.pop()
        c = b * a
        s.append(c)
    else:
        s.append(int(l[i]))

print(s[0])

Measured memory_bytes: 7688
from collections import deque
A = deque(input())
B = deque(input())
C = deque(input())
def check(moji):
    if moji == 'a':
        if len(A):
            return check(A.popleft())
        else:
            print("A")
    elif moji == 'b':
        if len(B):
            return check(B.popleft())
        else:
            print("B")
    elif moji == 'c':
        if len(C):
            return check(C.popleft())
        else:
            print("C")
check(A.popleft())

Measured memory_bytes: 3444