akhauriyash/Code-Regression huggingface dataset:
// Problem : D - Flat Subsequence
// Contest : AtCoder - ACL Beginner Contest
// URL : https://atcoder.jp/contests/abl/tasks/abl_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
//#define int long long
#define INF 1000000000000000000
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=1200004;
double pi=acos(-1.0);
int md=1e9+7;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};
//const int N=2e5;

template<class T>
T abst(T a)
{return a<0?-a:a;}

int Tree[N];
void build_max(int node,int start,int end,int a[]){
	if(start==end){
		Tree[node]=a[start];
		return;
	}
	int mid=((start+end)>>1);
	build_max(2*node+1,start,mid,a);
	build_max(2*node+2,mid+1,end,a);
	//According to the question,change from here
	Tree[node]=max(Tree[2*node+1],Tree[2*node+2]);
}
void update_max(int node,int start,int end,int i,int val){
	if(start==end){
		Tree[node]=val;
		return;
	}
	int mid=((start+end)>>1);
	if(i<=mid)
		update_max(2*node+1,start,mid,i,val);
	else
		update_max(2*node+2,mid+1,end,i,val);
	//According to the question,change from here
	Tree[node]=max(Tree[2*node+1],Tree[2*node+2]);
}
int query_max(int node,int start,int end,int l,int r){ 
	if(start>end||end<l||start>r)
		return 0;//0 in case of sum , high value in case of min , low value in case of max and soooo on 
	if(start>=l&&end<=r)
		return(Tree[node]);
	int mid = (start+end)/2 ; 
	int p1 = query_max(node*2+1, start, mid, l,r);
	int p2 = query_max(node*2+2, mid+1, end , l,r);
	return max(p1,p2);
}

void solve()
{
	int n,k;cin>>n>>k;
	int ans=1;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		int l=max(0,x-k);
		int r=min(300000,x+k);
		int mx=query_max(0,0,300000,l,r);
		ans=max(ans,mx+1);
		update_max(0,0,300000,x,mx+1);
	}
	cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 7748
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  int x = min(a + b + 1, c);
  cout << x + b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int x;
inline int read() {
   int x = 0, f = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9'){if (ch == '-')f = -1; ch = getchar();}
   while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
   return x * f;
}
int main() {
    x = read();
    int ans = 0;
    while(x){
        if(x % 10 == 2)ans++;
        x /= 10;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGCDSequence solver = new BGCDSequence();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGCDSequence {
        static final int m = 30;
        static final int BOUND = 30000;
        static final int[] initial = {5, 9, 16};
        static final int[] allowed = {2, 3, 4, 5, 6, 8, 9, 10, 12, 14};

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            List<Integer> answer = solve(n);

            StringBuilder sb = new StringBuilder();
            for (int x : answer) {
                sb.append(x + " ");
            }
            sb.deleteCharAt(sb.length() - 1);

            out.println(sb);
        }

        private static List<Integer> solve(int n) {
            int remaining = n;

            List<Integer> answer = new ArrayList<>(n);
            for (int x : initial) {
                answer.add(x);
                remaining--;
            }

            for (int mult = 3; mult * m <= BOUND && remaining > 0; mult++) {
                answer.add(mult * m);
                remaining--;
            }

            if (remaining % 2 == 1) {
                answer.add(m);
                remaining--;
            }

            int mult = 2;
            int next = 0;
            while (remaining > 0) {
                answer.add(mult * m + allowed[next]);
                answer.add(mult * m + (m - allowed[next]));
                remaining -= 2;
                next++;

                if (next == allowed.length) {
                    mult++;
                    next = 0;
                }
            }

            return answer;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 28116
#include <iostream>
#include <vector>

int main(void){
    int N, mn = 0, mx = 0;
    std::cin >> N;
    std::vector<int> A(9, 0);

    for (int i = 0; i < N; ++i){
        int a;
        std::cin >> a;
        a /= 400;
        if (a > 7) a = 8;
        ++A[a];
    }

    for (int i = 0; i < 8; ++i){
        if (A[i] > 0) ++mn;
    }

    mx += mn + A[8];
    if (mn == 0) ++mn;

    std::cout << mn << " " << mx << std::endl;

    return 0;
}


Measured memory_bytes: 3548
#include <string>
#include <iostream>
using namespace std;
string s;
int main() {
	while(s = "", getline(cin, s)) {
		string t;
		for(int i = 0; i < s.size(); i++) {
			switch(s[i]) {
				case 'A': t += "100101"; break;
				case 'B': t += "10011010"; break;
				case 'C': t += "0101"; break;
				case 'D': t += "0001"; break;
				case 'E': t += "110"; break;
				case 'F': t += "01001"; break;
				case 'G': t += "10011011"; break;
				case 'H': t += "010000"; break;
				case 'I': t += "0111"; break;
				case 'J': t += "10011000"; break;
				case 'K': t += "0110"; break;
				case 'L': t += "00100"; break;
				case 'M': t += "10011001"; break;
				case 'N': t += "10011110"; break;
				case 'O': t += "00101"; break;
				case 'P': t += "111"; break;
				case 'Q': t += "10011111"; break;
				case 'R': t += "1000"; break;
				case 'S': t += "00110"; break;
				case 'T': t += "00111"; break;
				case 'U': t += "10011100"; break;
				case 'V': t += "10011101"; break;
				case 'W': t += "000010"; break;
				case 'X': t += "10010010"; break;
				case 'Y': t += "10010011"; break;
				case 'Z': t += "10010000"; break;
				case ' ': t += "101"; break;
				case '\'': t += "000000"; break;
				case ',': t += "000011"; break;
				case '-': t += "10010001"; break;
				case '.': t += "010001"; break;
				case '?': t += "000001"; break;
			}
		}
		while(t.size() % 5 != 0) t = t + '0';
		string u;
		for(int i = 0; i < t.size(); i += 5) {
			int r = 0;
			for(int j = i; j < i + 5; j++) {
				r *= 2;
				if(t[j] == '1') r++;
			}
			if(r < 26) u += (char)(r + 65);
			else if(r == 26) u += ' ';
			else if(r == 27) u += '.';
			else if(r == 28) u += ',';
			else if(r == 29) u += '-';
			else if(r == 30) u += '\'';
			else u += '?';
		}
		cout << u << endl;
	}
}

Measured memory_bytes: 3004
N,Q=map(int,input().split())
S=input()

AC_number=[0 for _ in range(N+1)]
cnt=0
for i in range(1,N):
    if S[i]=="C" and S[i-1]=="A":
        cnt+=1
    AC_number[i+1]=cnt

for i in range(Q):
    l,r=map(int,input().split())
    print(AC_number[r]-AC_number[l])

Measured memory_bytes: 6180
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll N,K;
int main(){
    cin >> N >> K;
    vector<ll> x(N);
    rep(i,N) cin >> x[i];
    ll ans = 0, res = (ll)1e17;
    rep(i,N) if(i+K-1 <= N-1){
        int lp = i+K-1;
        if(x[i]*x[lp] >= 0) ans = max(abs(x[i]),abs(x[lp]));
        else ans = min(abs(x[i])*2+abs(x[lp]),abs(x[i])+abs(x[lp])*2);
        res = min(res,ans);
    }
    cout << res << '\n';
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        scanner.nextLine();
        String S = scanner.nextLine();

        long R = 0, G = 0, B = 0;
        for (int i = 0;i < N;i++) {
            if (S.charAt(i) == 'R') R++;
            else if (S.charAt(i) == 'G') G++;
            else B++;
        }

        long ans = R * G * B;
        for(int i = 0;i < N;i++) {
            int j = i-1, k = i+1;
            while (j >= 0 && k < N) {
                if(S.charAt(i) != S.charAt(j)
                        && S.charAt(j) != S.charAt(k)
                        && S.charAt(i) != S.charAt(k))
                    ans--;
                j--;k++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 37032
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int tmp = 1;
  	map<int, int> ma;
  	int ans[500][500] = {};
  	int x = 1, he = 1;
	while(tmp <= 100000){
    	ma[tmp] = x;
        for(int i = he; i <= tmp; i++){
          	ans[i-he][x-1] = i;
          	ans[x][i-he] = i;
        }
      	x++;
      	he = tmp+1;
	    tmp += x;
    }
  	
  	ll n;
  	cin >> n;
  	if(ma[n] > 0){
      	cout << "Yes" << endl << ma[n]+1 << endl;
      	REP(i, ma[n]+1){
          	cout << ma[n] << " ";
          	REP(j, ma[n]) cout << ans[i][j] << " ";
          	cout << endl;
        }
    }
  	else cout << "No" << endl;
}


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

int main(){
  int n;
  cin >> n;
  int a,b,c;
  c = n%10;
  b = (n/10)%10;
  a = (n/100)%10;
  if(a==7 or b==7 or c==7) cout<< "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define TRUE 1
#define FALSE 0
#define N 3


int P[N][N];
int dx[4] = {0,-1,0,1},dy[4] = {1,0,-1,0};
int lim;

int SUM();
void pazz(int,int);
void change(int,int,int,int);
int bfs(int,int,int,int);

int SUM()
{
  int i,j,num,sum=0;
  for(i=0;i<N;i++) {
    for(j=0;j<N;j++) {
      if(P[i][j] == 0)
	continue;
      num = P[i][j] - 1;
      sum += abs(num/N-i) + abs(num%N-j);
    }
  }
  return sum;
}


void pazz(int x,int y)
{
  for(lim=0;;lim++) {
    if(bfs(0,99,y,x)) {
      printf("%d\n",lim);
      return;
    }
  }
}

void change(int a,int b,int c,int d)
{
  int x;

  x = P[a][b];
  P[a][b] = P[c][d];
  P[c][d] = x;
}

int bfs(int d,int p, int y,int x)
{
  int i,j;
  int l,m,n;

  l = SUM();
  if(l == 0)
    return TRUE;
  if(lim < d + l)
    return FALSE;

  for(i=0;i<4;i++) {
    if(abs(i-p) == 2)
      continue;
    m = x + dx[i];
    n = y + dy[i];
    if(m < 0 || n < 0 || m >= N || n >= N)
      continue;
    change(n,m,y,x);
    

    if(bfs(d+1,i,n,m))
      return TRUE;
    change(n,m,y,x);
  }
    return FALSE;
}
    
    
 
  int main()
  {
    int i,j,x,y;

    for(i=0;i<N;i++){
      for(j=0;j<N;j++) {
	scanf("%d",&P[i][j]);
	if(P[i][j] == 0) {
	  y = i;
	  x = j;
	}
      }
    }
    pazz(x,y);
  
    return 0;
  }



Measured memory_bytes: 2148
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0

const ll inf = (ll)1e8;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int main() {
	int h, w;	cin >> h >> w;
	vector<string> a(h);
	rep(i, h)	cin >> a[i];
	vint cnt(26, 0);
	rep(i, h)	rep(j, w)	cnt[a[i][j] - 'a']++;
	int odd = 0, mod2 = 0;
	rep(i, 26) {
		if (cnt[i] & 1)	odd++;
		if (cnt[i] & 2)	mod2++;
	}
	if (odd >= 2) {
		cout << "No" << endl;
		return 0;
	}
	if (odd == 1 && h*w % 2 == 0) {
		cout << "No" << endl;
		return 0;
	}
	int can2 = (h % 2 == 1 ? floor(w / 2) : 0) + (w % 2 == 1 ? floor(h / 2) : 0);
	if (can2 < mod2) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000009;

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

	int l = 0;
	int r = 0;
	for(int i = 0;i < n;i++){
		if(l > 0 && s[i] == ')')l--;
		else if(s[i] == ')')r++;

		if(s[i] == '(')l++;
	}

	string ans = "";
	for(int i = 0;i < r;i++)ans += '(';
	ans += s;
	for(int i = 0;i < l;i++)ans += ')';

	cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int R = in.nextInt();
        int C = in.nextInt();
        int[][] V = new int[R][C];
        for (int K = in.nextInt(); K > 0; K--)
            V[in.nextInt() - 1][in.nextInt() - 1] = in.nextInt();
        long[][] max = new long[R][C];
        // r = 0
        long sum = 0;
        int[] top = new int[3];
        for (int c = 0; c < C; c++) {
            if (top[0] < V[0][c]) {
                sum -= top[0];
                top[0] = V[0][c];
                sum += top[0];
                Arrays.sort(top);
            }
            max[0][c] = sum;
        }
        for (int r = 1; r < R; r++) {
            for (int s = 0; s < C; s++) {
                if (V[r][s] == 0) {
                    max[r][s] = Math.max(max[r][s], max[r - 1][s]);
                    continue;
                }
                sum = max[r - 1][s];
                top = new int[3];
                for (int c = s; c < C; c++) {
                    if (top[0] < V[r][c]) {
                        sum -= top[0];
                        top[0] = V[r][c];
                        sum += top[0];
                        Arrays.sort(top);
                    }
                    max[r][c] = Math.max(max[r][c], sum);
                    if (top[0] > V[r][s]) break;
                }
            }
        }
        out.println(max[R-1][C-1]);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}


Measured memory_bytes: 179344
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str):
    for ch1 in S:
        count = 0
        for ch2 in S:
            if ch1 == ch2:
                count += 1
        if count != 2:
            print(NO)
            return
    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n = int(input())
a_lst = list(map(int,input().split()))
b_lst = list(map(int,input().split()))

taoseru_nokori = 0
taoshita = 0
for i in range(n):
	monster_maenoga_taoshita = min(a_lst[i],taoseru_nokori)
	monster_nokori = a_lst[i] - monster_maenoga_taoshita
	monster_taoshita = min(b_lst[i],monster_nokori)
	taoseru_nokori = b_lst[i] - monster_taoshita
	
	taoshita += monster_maenoga_taoshita + monster_taoshita

taoshita += min(a_lst[n],taoseru_nokori)
print(taoshita)


Measured memory_bytes: 82020
# coding: utf-8
# Your code here!
N=int(input())
S=[list(map(str,input().split())) for i in range(N)]

A=sorted(S,key=lambda x:int(x[1]), reverse=True)
B=sorted(A,key=lambda x:x[0])
#print(B)
for i in range(N):
    ans=S.index(B[i])+1
    print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define sp fixed<<setprecision
#define sz sizeof
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
ll fpow(ll x,ll y){x=x%MOD;ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  ll n,w;
  cin>>n>>w;
  ll dp[w+1];
  ll wt[n],val[n];
  for(int i=0;i<n;i++)
  cin>>wt[i]>>val[i];
  memset(dp,0,sizeof(dp));
  for(int i=0;i<n;i++)
  for(int j=w;j>=wt[i];j--)
  dp[j]=max(dp[j],dp[j-wt[i]]+val[i]);
  cout<<dp[w];
}


Measured memory_bytes: 1024
unittest
{
	assert( [ "3 2", "4 1 5" ].solve == 3 );
	assert( [ "13 17", "29 7 5 7 9 51 7 13 8 55 42 9 81" ].solve == 6 );
	assert( [ "10 400000000", "1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000" ].solve == 25 );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	auto ts = new long[ 1 + as.length ];
	foreach( i, a; as )
	{
		ts[ i + 1 ] = ts[ i ] + a;
	}
	
	auto ans = 0L;
	long[ long ] rs;
	foreach( i, t; ts )
	{
		auto r = t % m;
		if( r in rs ) ans += rs[ r ];
		rs[ r ]++;
	}
	return ans;
}


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

int main() {
  int n,r;
  cin>>n>>r;
  int ty=100*(10-n);
  
  if(n<10){
  	cout<<r+ty<<endl;
  }
  
  else{
  	cout<<r<<endl;
  }
	
}

Measured memory_bytes: 256
import math as M
A,B=map(int,input().split(' '))
list=list(map(str,input().split(('-'))))
if list.__len__() != 2:
    print("No")
else:
   if list[0].__len__()==A and list[1].__len__()==B:
       print("Yes")
   else:
       print("No")



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

int main(){
  double heikin;
  int heikin2;
  double a, b;
  cin>>a>>b;
  heikin=(a+b)/2;
  heikin2=(a+b)/2;
  if(heikin-heikin2==0){
    cout<<heikin2<<endl;
  }
  else{
    cout<<heikin2+1<<endl;
  }
}


Measured memory_bytes: 256
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
while ans < n:
    ans += 1000
print(ans-n)

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

int main() {
  int A,B;
  cin >> A >> B;
  if(A * B % 2 == 0) cout << "Even" << endl;
  else cout << "Odd" << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);


int main() {
	cin.sync_with_stdio(false);
	int H, W, D;
	cin >> H >> W >> D;
	map<int, pair<int, int>>mp;
	rep(i, H) {
		rep(j, W) {
			int A;
			cin >> A;
			A--;
			mp[A] = { i,j };
		}
	}
	vector<vector<ll>>c(D);
	rep(i,D) {
		int cnt = 1;
		ll pre = 0;
		ll pre_1 = mp[i].first, pre_2 = mp[i].second;
		while (i + D*cnt < H*W) {
			int num = i + D*cnt;
			pre += abs(pre_1 - mp[num].first) + abs(pre_2 - mp[num].second);
			c[i].push_back(pre);
			cnt++;
			pre_1 = mp[num].first; pre_2 = mp[num].second;
		}
	}
	int Q;
	cin >> Q;
	vector<ll>ans(Q);
	rep(i, Q) {
		int L, R;
		cin >> L >> R;
		L--; R--;
		int l = L%D;
		int num1 = L / D - 1;
		int num2 = R / D - 1;

		if (num1 >= 0)ans[i] -= c[l][num1];
		if (num2 >= 0)ans[i] += c[l][num2];
	}
	rep(i, Q)cout << ans[i] << endl;


	return 0;
}


Measured memory_bytes: 8960
def smaller(a, b)
    if a < b then
        return a
    else
        return b
    end
end
input = STDIN.readlines.map{|line|line.strip.split()}
line = input.shift

n = line[0].to_i
a = line[1].to_i
b = line[2].to_i
c = line[3].to_i
l_list = input.map{|i|i[0].to_i}
usage = [0, 1, 2, 3]
stack = [[0, 0, 0, 0, 0]]
min = 10**9
while stack.size > 0 
    temp = stack.pop
    if temp[0] == n then
        if temp[1] > 0 && temp[2] > 0 && temp[3] > 0 then
            min = smaller(min, (a - temp[1]).abs + (b - temp[2]).abs + (c - temp[3]).abs + temp[4] - 30)
        end
    else
        stack.push([temp[0] + 1, temp[1] + l_list[temp[0]], temp[2], temp[3], temp[4] + 10])  
        stack.push([temp[0] + 1, temp[1], temp[2] + l_list[temp[0]], temp[3], temp[4] + 10])  
        stack.push([temp[0] + 1, temp[1], temp[2], temp[3] + l_list[temp[0]], temp[4] + 10])  
        stack.push([temp[0] + 1, temp[1], temp[2], temp[3], temp[4]])
    end
end

puts(min)

Measured memory_bytes: 2044
P,Q,R =  list(map(int,input().split()))

min=P+Q


if(P+Q > Q+R):
    min = Q+R
    
    if(Q+R > P+R):
        min = P+R

if(P+Q > P+R):
    min = P+R
    
    if(P+R > Q+R):
        min = Q+R

print(min)

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

int main(){


    long long num1,num2,rem,lcm,gcd,n1,n2;
     cin>>num1;
        cin>>num2;
        n1 = num1;
        n2 = num2;


    while(n2!=0)
    {

        rem = n1%n2;
        n1 = n2;
        n2 = rem;


    }
      gcd = n1;

      lcm = (num1 * num2)/gcd;
      cout<<lcm;


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,ans,mx[800005],tag[800005];
struct ii
{
	int l,r;
}a[200005];
bool cmp(ii x,ii y){return x.l<y.l;}
void pushup(int x){mx[x]=max(mx[x+x],mx[x+x+1]);}
void upd(int x,int y){mx[x]+=y;tag[x]+=y;}
void pushdo(int x){if(tag[x]){upd(x+x,tag[x]);upd(x+x+1,tag[x]);tag[x]=0;}}
void build(int x,int l,int r)
{
	tag[x]=0;
	if(l==r){mx[x]=-(m-l+1);return;}
	int mid=(l+r)/2;
	build(x+x,l,mid);
	build(x+x+1,mid+1,r);
	pushup(x);
}
void update(int x,int l,int r,int ql,int qr,int c)
{
	if(ql<=l&&r<=qr){upd(x,c);return;}
	int mid=(l+r)/2;pushdo(x);
	if(ql<=mid) update(x+x,l,mid,ql,qr,c);
	if(qr>mid) update(x+x+1,mid+1,r,ql,qr,c);
	pushup(x);
}
int query(int x,int l,int r,int ql,int qr)
{
	if(ql<=l&&r<=qr)return mx[x];
	int mid=(l+r)/2;pushdo(x);
	if(qr<=mid)return query(x+x,l,mid,ql,qr);
	if(ql>mid)return query(x+x+1,mid+1,r,ql,qr);
	return max(query(x+x,l,mid,ql,qr),query(x+x+1,mid+1,r,ql,qr));
}
int main()
{
	scanf("%d%d",&n,&m);
	ans=max(0,n-m);
	fz1(i,n)scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+n+1,cmp);
	build(1,0,m+1);
	fz1(i,n){
		update(1,0,m+1,0,a[i].r,1);
		if(i==n||a[i].l!=a[i+1].l){
			if(a[i].l+2<=m+1) ans=max(ans,query(1,0,m+1,a[i].l+2,m+1)-a[i].l);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7040
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


n,m=map(int,readline().split())

print((n*(n-1))//2+m*(m-1)//2)

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

vector<int> topo;

vector<int> node[100000];
int done[100000];
void dfs(int p) {
  if (done[p]++) return;
  for (int i : node[p])
    dfs(i);
  topo.push_back(p);
}

int dp[100000];
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    node[a].push_back(b);
  }
  for (int i = 0; i < n; i++)
    dfs(i);
  int ans = 0;
  for (int p : topo) {
    for (int i : node[p])
      ans = max(ans, dp[p] = max(dp[p], dp[i]+1));
  }
  cout << ans << endl;
}


Measured memory_bytes: 9080
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int a[4],s2,s1,s;
    	scanf("%d %d %d",&a[0],&a[1],&a[2]);
    	sort(a,a+3);
    	s2=(a[2]-a[1])/2+(a[2]-a[0])/2;
    	s1=(a[2]-a[1])%2+(a[2]-a[0])%2;
    	s=s2+s1/2;
    	if(s1%2!=0)
    		s+=2;
    	printf("%d",s);
    	return 0;
    }

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

#define CO const
#define IN inline
typedef long long LL;
typedef long double LD;

template<class T> T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}
#define gcd __gcd

CO int mod=1e9+7;
IN int add(int a,int b){
	return (a+=b)>=mod?a-mod:a;
}
IN int mul(int a,int b){
	return (LL)a*b%mod;
}
IN int fpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=mul(a,a))
		if(b&1) ans=mul(ans,a);
	return ans;
}

CO int N=500;
vector<int> to[N];
int E[N][N];
int pos[N],low[N],dfn,stk[N],top;
vector<int> vcc[N];
int tot;

void tarjan(int u,int fa){
	pos[u]=low[u]=++dfn,stk[++top]=u;
	for(int v:to[u]){
		if(!pos[v]){
			tarjan(v,u);
			low[u]=min(low[u],low[v]);
			if(low[v]>=pos[u]){
				vcc[++tot].push_back(u);
				do vcc[tot].push_back(stk[top]);
				while(stk[top--]!=v);
			}
		}
		else low[u]=min(low[u],pos[v]);
	}
}

int K,C[N][N];

int circle(int n){
	int ans=0;
	for(int i=0;i<n;++i) ans=add(ans,fpow(K,gcd(n,i)));
	ans=mul(ans,fpow(n,mod-2));
	return ans;
}
int calc(CO vector<int>&vcc){
	if(vcc.size()==2) return K;
	int cnt=0;
	for(int u:vcc)for(int v:vcc)
		cnt+=E[u][v];
	cnt/=2;
	if(cnt==(int)vcc.size()) return circle(cnt);
	return C[cnt+K-1][K-1];
}
int main(){
	int n=read<int>(),m=read<int>();read(K);
	for(int i=1;i<=m;++i){
		int u=read<int>(),v=read<int>();
		E[u][v]=E[v][u]=1;
		to[u].push_back(v),to[v].push_back(u);
	}
	for(int i=1;i<=n;++i)if(!pos[i]) tarjan(i,0);
	for(int i=0;i<=m+K;++i){
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;++j) C[i][j]=add(C[i-1][j-1],C[i-1][j]);
	}
	int ans=1;
	for(int i=1;i<=tot;++i) ans=mul(ans,calc(vcc[i]));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    vector<int> V(3, 0);
    for (int i = 0; i < 3; i++) cin >> V[i];
    sort(V.begin(), V.end());
    printf("%d\n", V[0] + V[1]);
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int sum = 0;
            int[] d = new int[n];
            for (int i = 0; i < n; i++)
                d[i] = in.nextInt();
            for (int i = 0; i < n - 1; i++)
                for (int j = i + 1; j < n; j++)
                    sum += d[i] * d[j];
            out.println(sum);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21204
package main

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

var sc = bufio.NewScanner(os.Stdin)

// 一行読み出し
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

// 文字列リバース関数
func strReverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

// スペース区切りの文字列から int のスライスを得る
func intSlice(s string) []int {
	ss := strings.Split(s, " ")
	res := make([]int, len(ss))
	for i, v := range ss {
		iv, _ := strconv.Atoi(v)
		res[i] = iv
	}

	return res
}

func main() {

	var s string
	fmt.Scan(&s)


	m := make(map[rune]int)
	for _, v := range s {
		m[v]++
	}


	ans := "Yes"
	if len(m) == 2 {
		for _, v := range m {
			if v != 2 {
				ans = "No"
			}
		}
	} else {
		ans = "No"
	}
	fmt.Println(ans)
}



Measured memory_bytes: 640
class unionFind():
	def __init__(self,n):
		self.tree=[-1]*n
	def find(self,x):
		if self.tree[x]<0:
			return x
		else:
			return self.find(self.tree[x])
	def union(self,x,y):
		xr=self.find(x)
		yr=self.find(y)
		if xr!=yr:
			if self.tree[xr]<self.tree[yr]:
				self.tree[yr]=xr
			elif self.tree[xr]>self.tree[yr]:
				self.tree[xr]=yr
			else:
				self.tree[xr]-=1
				self.tree[yr]=xr
			return True
		
		return False
def main():
	ans=0
	n,m=map(int,input().split())
	a=unionFind(n)
	li=[x-1 for x in list(map(int,input().split()))]
	for _ in range(m):
		x,y=map(int,input().split())
		a.union(x-1,y-1)
	for x in range(n):
		ans += a.find(x)==a.find(li[x])
	return ans
print(main())


Measured memory_bytes: 14580
def fnc(i, num):
    if i == 4:
        if num == 7:
            return True
        else:
            return False
    
    if fnc(i+1, num + n[i]):
        st.insert(1, "+" + str(n[i]))
        return True
    
    if fnc(i+1, num - n[i]):
        st.insert(1, "-" + str(n[i]))
        return True

n = list(map(int, input()))
st = [str(n[0]), "=7"]
fnc(1, n[0])
print(''.join(st))


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

int main(){
  int h, m, s, S;
  cin >> S;

  h = S / 3600;
  m = (S - h*3600) / 60;
  s = S - h*3600 - m*60;

  cout << h << ":";
  cout << m << ":";
  cout << s << endl;
  return 0;
}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend()
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

int main(){
  int N; cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
    return 0;
  }
  else{
    int a, b; cin >> a >> b;
    cout << (a + b) << endl;
  }
}


Measured memory_bytes: 256
function Main(input) {
    let [A,B,C,D] = input.split(" ").map(e => Number(e));
    const battle = () => {
        if (index % 2 === 0) {
            C -= B
        } else {
            A -= D
        }
        index ++
    }
    let index = 0;
    while (A > 0 && C > 0) {
        battle()
    }
    console.log(index % 2 === 1 ? "Yes" : "No")
}
// Main("46 4 40 5")
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29632
import  math
while(True):
    n=int(input())
    if n==0:
        exit()
    s=list(map(int,input().split()))

    ave=sum(s)/n
    v=0
    for i in range(n):
       v+=(s[i]-ave)**2

    v/=n
    print(math.sqrt(v))


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

signed main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int strsize = (int)S.size();
  
  bool hantei = true;
  for( int i = 0; i < min(strsize, K); i++ ){
    if( S.at(i) != '1' ){
      hantei = false;
      cout << S.at(i) << endl;
      return 0;
    }
  }
  
  if( hantei == true ) cout << 1 << endl;
  
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  cout << max(A*B,C*D) << endl;

  return 0;
}


Measured memory_bytes: 256
(_,N,K),H = $<.map{|l|[0]+l.split.map(&:to_i)}
Memo = H.map{|i|[0,i]}
def dfs(x,y)
  Memo[x][y]||=(y-1..x-1).map{|i|dfs(i,y-1)+[0,H[x]-H[i]].max}.min
end
p (N-K..N).map{|i|dfs(i,N-K)}.min

Measured memory_bytes: 6140
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int n;
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d%d%d", &a, &b, &c);
		
		if (a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b){
			printf("YES\n");
		}
		else printf("NO\n");
	}
	
	return (0);
	
}

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

int bubbleSort(int A[], int n){
    int count = 0;
    bool flag = 1;

    while(flag){
        flag = 0;
        for(int i = n-1; i > 0; i--){
            if(A[i] < A[i-1]){
                swap(A[i], A[i-1]);
                count++;
                flag = 1;
            }
        }
    }

    return count;
}

int main(){
    int A[100], n, count;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    count = bubbleSort(A,n);

    for(int i = 0; i < n; i++){
        if(i)   cout << " ";
        cout << A[i];
    }

    cout << endl;
    cout << count << endl;

    return 0;
}


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

///////////////////////////////////////////
const int INF = 1000000000;
using ll = long long int;
using vi = vector<int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
//template <class  T>T max(T x,T y){if(x>y){return x;}else{return y;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
///////////////////////////////////////////

ll num[200001];
int dp[200001];
ll pls;

//int rec(int x){
//   // cout<<x<<endl;
//    if(x<0)return pls;
//    if(dp[x]>=0)return dp[x];
//    dp[x] = min(abs(rec(x-1)),abs(rec(x-1)-2*num[x]));
//    return dp[x];
//}

int main(){
    memset(dp,-1, sizeof(dp));
    ll n;
    cin>>n;
    pls=0;
    cin>>num[0];
    pls=num[0];
    for(int i=1;i<n;i++){cin>>num[i];pls+=num[i];num[i]+=num[i-1];}
    ll ans=1000000000000000000LL;
    for (int i = 0; i < n-1; i++) {
        chmin(ans,abs(pls - 2*num[i]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
import java.util.*;

class Main{

    int n, m, sz;
    char[] kakko;
    int[] a, bkt, add;

    void solve(){
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        m = sc.nextInt();
        kakko = sc.next().toCharArray();

        sz = Math.max(1, (int)Math.sqrt(n) + 10);
        a = new int[n];
        bkt = new int[n/sz+1];
        Arrays.fill(bkt, Integer.MAX_VALUE);
        add = new int[n/sz+1];
        TreeSet<Integer> set = new TreeSet<Integer>();

        for(int i=0; i<n; i++){
            if(i==0) a[i] = 1;
            else{
                if(kakko[i]=='(') a[i] = a[i-1] + 1;
                else{
                    a[i] = a[i-1] - 1;
                    set.add(i);
                }
            }
            bkt[i/sz] = Math.min(a[i], bkt[i/sz]);
        }

        for(int i=0; i<m; i++){
            int q = sc.nextInt()-1;
            int idx = 0;
            if(kakko[q]=='('){
                kakko[q] = ')';
                set.add(q);
                add(q, n, -2);
                //idx = set.higher(new Integer(-1));
                idx = set.pollFirst();
                kakko[idx] = '(';
                set.remove(idx);
                add(idx, n, 2);
            }else{
                kakko[q] = '(';
                set.remove(q);
                add(q, n, 2);
                idx = search(q);
                kakko[idx] = ')';
                add(idx, n, -2);
                set.add(idx);
            }
            //System.out.println(Arrays.toString(kakko));
            System.out.println(idx+1);
        }
    }

    void add(int start, int last, int num){
        int from = start - start%sz;
        int to = from + sz;
        for(int i=start/sz; i * sz <=last; i++){
            if(start<=from && to<=last){
                add[i] += num;
            }else{
                for(int j=Math.max(from, start); j<to && j<last; j++){
                    a[j] += num;
                }
                int min = Integer.MAX_VALUE;
                for(int j=from; j<to && j<a.length; j++){
                    min = Math.min(min, a[j]);
                }
                bkt[i] = min;
            }
            from = to;
            to += sz;
        }
    }

    int search(int f){        
        int from = f - f%sz;
        int to = from + sz;
            
        for(int i=f/sz; i>=0; i--){
            if(bkt[i]+add[i]<=1){
                for(int j=Math.min(f-1, to-1); j>=from; j--){
                    if(a[j]+add[i]==1) return j+1;
                }
            }
            to = from;
            from -= sz;
        }
        return 0;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 113216
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;

const string LDUR = "LDUR";
int main() {
	int n;
	cin >> n;
	int mod2 = -1;
	bool canConsist = true;
	
	vector<int> u(n);
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;

		if (abs(x + y) % 2 != mod2 && mod2 >= 0) {
			canConsist = false;
			break;
		}
		else if (mod2 < 0) {
			mod2 = abs(x + y) % 2;
		}

		u[i] = x + y;
		v[i] = x - y;
		
	}


	if (!canConsist) {
		cout << -1 << endl;
	}
	
	else {

		if (mod2 == 0) {
			cout << 32 << endl;
		}
		else {
			cout << 31 << endl;
		}
		
		for (int i = 30; i >=0;i--) {
			cout << (1 << i) << " ";
		}
		if (mod2 ==0) {
			cout << 1;
		}
		cout << endl;
		for (int i = 0; i < n;i++) {
			ll ui = (u[i] + (1LL << 31) - 1) / 2;
			ll vi = (v[i] + (1LL << 31) - 1) / 2;
			if (mod2 == 0) {
				ui = (u[i] + (1LL << 31)) / 2;
				vi = (v[i] + (1LL << 31)) / 2;
			}
			string ans;
			for (int i = 30; i  >=0;i--) {
				//printf("%x\n", ui);
				int ub = (ui >> i) & 1;
				//cout << ub << endl;
				int vb = (vi >> i) & 1;
				//cout << ub << endl;
				ans += LDUR[ub * 2 + vb];
			}
			if (mod2 == 0) {
				ans += LDUR[0];
			}

			cout << ans << endl;
		}
	}

}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int a, b;
  cin >> a >> b;
  int c = a * b;
  if (c % 2 == 0)
  {
    cout << "Even" << endl;
  }
  else
  {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 3516
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int dy[2] = {1,0};
int dx[2] = {0,1};
int h,w;
vector<string>s(10);

int main(){
    int n;cin>>n;
    int res = INF;
    REP(i,1,n-1){
        int a = i,b = n-i;
        int c = 0;
        while(a){
            c += a%10;
            a /= 10;
        }
        while(b){
            c += b%10;
            b /= 10;
        }
        res = min(res,c);
    }
    cout<<res<<endl;
}



Measured memory_bytes: 256
def lscan; gets.split.map(&:to_i); end

n = gets.to_i
aa = lscan

if aa.sort == aa
  puts 'YES'; exit
end

(0...n).to_a.combination(2) do |a, b|
  aa[a], aa[b] = aa[b], aa[a]
  if aa.sort == aa
    puts 'YES'; exit
  end
  aa[a], aa[b] = aa[b], aa[a]
end
puts 'NO'


Measured memory_bytes: 2044