akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
using namespace std;
int n,m,i,j,k;
int a[100],b[100];
bool g[100][100];
bool f[10];

int dfs(int num,bool flg []){
  int i;
  int ans=0;
  bool flg2[10];
  bool fl=true;
  for (i=0;i<n;i++){
    flg2[i]=flg[i];
    if (!flg2[i]){fl=false;}
  }
  if (fl){return 1;}
  for (i=0;i<n;i++){
    if (!flg2[i] && g[num][i]){
        flg2[i]=true;
        ans+=dfs(i,flg2);
        flg2[i]=false;

    }
  }
  return ans;

}

int main(){
  scanf("%d %d",&n,&m);
  for (i=0;i<n;i++){
    for (j=0;j<n;j++){
      g[i][j]=false;
    }
  }
  for (i=0;i<m;i++){
    int t0,t1;
    scanf("%d %d",&t0,&t1 );
    g[t0-1][t1-1]=true;
    g[t1-1][t0-1]=true;
  }
  for (i=0;i<n;i++){f[i]=false;}
  f[0]=true;
  int ans=dfs(0,f);
  printf("%d\n",ans );
}


Measured memory_bytes: 128
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var):
    print(*var, file=sys.stderr)

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
# from collections import defaultdict as dd, Counter
# from bisect import bisect_left as bl, bisect_right as br

n, = I()
if n % 2:
    print(0)
    exit()

n //= 2
ans = 0
for i in range(1, 100):
    ans += n//(5**i)
print(ans)

Measured memory_bytes: 38384
/*    created: 17.07.2020 01:31:48    */

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

ll h, w, k, ans = 0;
vector<int> A;

int main(){
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];

    for(int i = 0; i < (1 << h); i++){
        for(int j = 0; j < (1 << w); j++){
            ll cnt = 0;
            for (int a = 0; a < h; a++){
                for (int b = 0; b < w; b++){
                    if (i&(1 << a) || j&(1 << b)) continue;
                    if (c[a][b] == '#') cnt++;
                }
            }
            if(cnt == k) ans++;
        }
    }
    cout << ans << endl;
}

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

int main() {
  std::string s;
  std::cin >> s;

  uint A = 0;
  for (size_t i = 0; i < s.length(); i++) {
    if (s[i] == 'A') {
      A = i;
      break;
    }
  }

  uint Z = 0;
  for (size_t i = s.length() - 1;; i--) {
    if (s[i] == 'Z' || i == 0) {
      Z = i;
      break;
    }
  }

  std::cout << Z - A + 1 << std::endl;

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int a[101],b[101];
int main(){   
    int n,i,j,ans=0;
    cin>>n;
    for(i=0;i<n;i++){
    	cin>>a[i];
	} 
	for(j=0;j<n;j++){
		cin>>b[j];
	}
    
    for(int i=0;i<n;i++){
        a[i]=a[i]+a[i-1];
    }
    reverse(b,b+n);
    for(int i=1;i<n;i++){
    	b[i]=b[i]+b[i-1];
	}
    for(int i=0;i<n;i++){
        int t=a[i]+b[n-1-i];
        ans=max(ans,t);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static class P {
		int x;
		int y;
		int d;

		P(int x, int y, int d) {
			this.x = x;
			this.y = y;
			this.d = d;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		sc.nextLine();

		int[][] visited = new int[h][w];
		for (int i = 0; i < h; i++) {
			Arrays.fill(visited[i], Integer.MAX_VALUE);
		}

		char[][] a = new char[h][w];
		int count = 0;
		for (int hi = 0; hi < h; hi++) {
			String s = sc.nextLine();
			a[hi] = s.toCharArray();
			for (int i = 0; i < w; i++) {
				if (a[hi][i] == '#') count++;
			}
		}

		Queue<P> q = new LinkedList<>();
		q.offer(new P(0, 0, 1));
		while (!q.isEmpty()) {
			P p = q.poll();
			if (p.x < 0 || p.y < 0 || p.x >= w || p.y >= h) continue;
			if (a[p.y][p.x] == '#') continue;
			if (visited[p.y][p.x] <= p.d) continue;
			visited[p.y][p.x] = p.d;
			q.offer(new P(p.x + 1, p.y, p.d + 1));
			q.offer(new P(p.x, p.y + 1, p.d + 1));
			q.offer(new P(p.x - 1, p.y, p.d + 1));
			q.offer(new P(p.x, p.y - 1, p.d + 1));
		}

		//for (int i = 0; i < h; i++) {
		//	for (int j = 0; j < w; j++) {
		//		System.out.print(visited[i][j]);
		//		System.out.print(" ");
		//	}
		//	System.out.println();
		//}

		if (visited[h - 1][w - 1] == Integer.MAX_VALUE) {
			System.out.println(-1);
		} else {
			System.out.println(h * w - count - visited[h - 1][w - 1]);
		}
	}
}


Measured memory_bytes: 21844
stack = []
input = gets.chomp.split(" ")
for i in 1..input.size do
  s = input[i-1]
  case s
  when "+" then
    stack.push(stack.pop + stack.pop)
  when "-" then
    stack.push(- stack.pop + stack.pop)
  when "*" then
    stack.push(stack.pop * stack.pop)
  else
    stack.push(s.to_i)
  end 
end
printf("%d\n",stack.pop)


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

#define MAX_N 100005

vector <int> adj[MAX_N];
int dis1[MAX_N];
int dis2[MAX_N];
bool vis1[MAX_N];
bool vis2[MAX_N];

void dfs1(int u)
{
    vis1[u] = true;
    for (int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if (!vis1[v]) {
            dis1[v] = dis1[u] + 1;
            dfs1(v);
        }
    }
}

void dfs2(int u)
{
    vis2[u] = true;
    for (int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if (!vis2[v]) {
            dis2[v] = dis2[u] + 1;
            dfs2(v);
        }
    }
}

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1(1);
    dfs2(n);
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++) {
        if (dis1[i] <= dis2[i]) cnt1++;
        else cnt2++;
    }
    if (cnt1 > cnt2) printf("Fennec\n");
    else printf("Snuke\n");
    return 0;
}


Measured memory_bytes: 11392
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int cnt = 0;
		for(int i = 0; i < H; i++) {
			String s = sc.next();
			for(int j = 0; j < W; j++) {
				if(s.charAt(j) == '#') {
					cnt++;
				}
			}
		}
		sc.close();
		if(cnt == H + W - 1) {
			System.out.println("Possible");
		}else {
			System.out.println("Impossible");
		}
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
    }

    sort(a, a+n);
    reverse(a, a+n);

    ll x = -1, y = -1, ans;
    ll t = a[0];
    int k = 0;
    rep(i, n) {
        if(t != a[i]) {
            t = a[i];
            k = 0;
        }
        k++;
        if(k >= 2) {
            if(x == -1LL) {
                x = a[i];
            }
            else if(y == -1LL) {
                y = a[i];
            }
            k = 0;
        }
        if(y != -1LL) {
            break;
        }
    }

    if(y == -1LL) {
        ans = 0;
    }
    else {
        ans = x*y;
    }

    cout << ans;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
/****************************************************************************************
	test003.c: #003 ITP1_1_C
	  function: Rectangle

 ****************************************************************************************/
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // exit(), free()
#include <stdbool.h>
#include <errno.h>          // errno
#ifdef linux
 #include <error.h>         // error()
#endif

const char NUL = '\0';
int lineno;
char* linebuff = NULL;
size_t linebuffsize = 0;

void
cleanup(int ecode)
{
	if (linebuff)
	{
		free(linebuff);
		linebuff = NULL;
		linebuffsize = 0;
	}

	exit(ecode);
}

void
skip_sp(const char** p)
{
	while (**p == ' ')
		(*p)++;
}

bool
ope_line(const char* linebuff)
{
	char* nextp = NULL;

	const char* s = linebuff;
	if (*s == NUL)
		return false;

	lineno++;
	skip_sp(&s);
	int a = strtol(s, &nextp, 10);
	s = nextp;
	skip_sp(&s);
	int b = strtol(s, &nextp, 10);
	s = nextp;

	printf("%d %d\n", a * b, (a + b) * 2);

	skip_sp(&s);
	if (*s == NUL)
		return false;

	return true;
}

int
main(int argc, char** argv)
{
	lineno = 0;
	while (true) // process for each line
	{
		errno = 0;
		if(getline(&linebuff, &linebuffsize, stdin) == -1) // read line
		{
			if(errno == 0)  // EOF?
				break;

#ifdef linux
			error(0, errno, "Can't read line");
#else
			fprintf(stderr, "Can't read line\n");
#endif
			cleanup(1);
		}

		if (!ope_line(linebuff))
			break;
	}

	cleanup(0);
	return 0;
}

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

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

vector< pair<int,int> > v;
int main(){
	int n,x; cin>>n;
	for(int i = 0; i < n; i++){
		cin>> x;
		v.push_back(make_pair(x,i));
	}
	sort(v.begin(),v.end());
	for(int i = 0; i < n; i++){
		cout<<v[i].second+1<<" ";
	}
	return 0;
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
i64 n,x;
cin>>n;
i64 pr=1;
bool is1=false,is2=false;
i64 mx=1e18;
forn(i,n)
{
cin>>x;

// cout<<x<<" "<<(mx/pr)<<"\n";
if(x==0)
{
  is2=true;
  pr=0;
  break;
}
if(pr>mx||x>(mx/pr)||is1)
{
is1=true;


}
else
pr*=x;
  }
// cout<<is1<<" "<<is2<<" ";
  if(is1&&!is2)cout<<"-1";
else cout<<pr;


    return 0;
  }


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

int main(void){
	string str;
	char aba[9][9];
	bool ch=false;
	while(cin >> str){
		if(ch==true)printf("\n");
		string str2;
		for(int i=str.size();i<5;i++){
			str2+="0";
		}
		str2+=str;
		memset(aba,'\0',sizeof(aba));
		for(int i=0;i<str2.size();i++){
			if(str2[i]<'5')aba[i][0]='*',aba[i][1]=' ';
			else aba[i][0]=' ',aba[i][1]='*';
			aba[i][2]='=';
			for(int j=3;j<8;j++){
				if(j-3==(str2[i]-'0')%5)aba[i][j]=' ';
				else aba[i][j]='*';
			}
		}
		for(int i=0;i<8;i++){
			for(int j=0;j<str2.size();j++){
				printf("%c",aba[j][i]);
			}
			printf("\n");
		}
		ch=true;
	}
    return 0;
}

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

int main(){
char c[3][3];
REP(i,3){
    REP(j,3){
        cin>>c[i][j];
    }
}

cout<<c[0][0]<<c[1][1]<<c[2][2]<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;cin>>n>>m;
  ll a[n];
  for(ll i=0;i<n;i++){
    cin>>a[i];
    a[i]%=m;
  }
  map<ll,ll>mp;
  mp[0]++;
  ll sum=0;
  ll ans=0;
  for(ll i=0;i<n;i++){
    sum+=a[i];
    sum%=m;
    ans+=mp[sum];
    mp[sum]++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4992
def match_num(s, part_s):
    match = 0
    for (s_char, part_s_char) in zip(s, part_s):
        if s_char == part_s_char:
            match += 1

    return match


s = input()
t = input()

max_match = 0

for i in range(len(s)):
    if i+len(t) > len(s):
        break
    part_s = s[i:i+len(t)]
    match = match_num(t, part_s)
    if match > max_match:
        max_match = match

print(len(t)-max_match)



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

int main(){
    string s, t;
    cin >> s >> t;

    vector<vector<int>> dp(3001, vector<int>(3001));
    for(int i=0; i<s.length(); i++){
        for(int j=0; j<t.length(); j++){
            if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
            else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
    }
    //cout << dp[s.length()][t.length()] << endl;

    string ans = "";
    int x = s.length(), y = t.length();
    while(x > 0 && y > 0){
        //cout << "dp[" << x << "][" << y << "] = " << dp[x][y] << ", str = ";

        if     (dp[x][y] == dp[x-1][y]) x -= 1;
        else if(dp[x][y] == dp[x][y-1]) y -= 1;
        else{//if(dp[x][y] == dp[x-1][y-1] + 1)
            ans = s[x-1] + ans;
            x -= 1;
            y -= 1;
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    bool p[110] = {0};
    int x, n; cin >> x >> n;
    rep(i, n) {
        int a; cin >> a;
        p[a] = 1;
    }
    rep(i, 110) {
        if(!p[x-i]) {
            cout << x-i << endl;
            return 0;
        }
        if(!p[x+i]) {
            cout << x+i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3580
#include<iostream>
using namespace std;
int main(){
	int h,v,k;
  	cin>>h>>v>>k;
  	string s[h];
  	for(int i=0;i<h;i++)cin>>s[i];
  	int ans=0;
  	for(int i=0;i<(1<<h);i++){
  		for(int j=0;j<(1<<v);j++){
    		int cnt=0;
      		for(int p=0;p<h;p++){
        		for(int q=0;q<v;q++){
            		if(s[p][q]=='#'&&!((i+1)&(1<<p))&&!((j+1)&(1<<q)))cnt++;
           		}
        	}
        if(cnt==k)ans++;
    	}
  	}
  	cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <time.h>
#include<string>
using namespace std;
int main(){
	char tile[101][101];
	int dp[101][101]={0};
	bool finished=false;
	int x,y;
	while(1){
		cin>>y>>x;
		memset(dp,0,sizeof(dp));
		finished=false;
		if(y==0 && x==0){
			break;
		}
		for(int i=0;i<y;i++){
			for(int j=0;j<x;j++){
				cin>>tile[i][j];
			}
		}int i=0,j=0;
		while(1){
			switch(tile[i][j]){
			case '>': j++ ;dp[i][j]++;break;
			case '<': j--;dp[i][j]++;break;
			case '^': i--;dp[i][j]++;break;
			case 'v': i++;dp[i][j]++;break;
			case '.': cout<<j<<" "<<i<<endl;finished=true; break;
			}
			if(finished==true){
				break;
			}
			if(dp[i][j]==2){
				cout<<"LOOP"<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3080
import sys
O = pow(10, 18)
N = int(input())
L = list(map(int, input().split()))
M = 1

if 0 in L:
    print(0)
    sys.exit()

for i in range(N):
    M = M * L[i]
    if O < M:
        print(-1)
        sys.exit()
    else:
        continue
print(M)

Measured memory_bytes: 21804
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

const int MAX_LIMIT = 100005;

int N;
bool isPossible = 1;
int arr[MAX_LIMIT];

ll modPow(ll base, ll expo)
{
    long long r=1;
    while(expo){
        if(expo&1){
            r=(r*base)%MOD;
        }
        base=(base*base)%MOD;
        expo>>=1;
    }
    return r % MOD;
}

int main()
{
	int i, j;

	si(N);

	fl(i,0,N)
	{
		si(arr[i]);
	}

	sort(arr, arr + N);
	int start;
	if(N % 2 == 0)
	{
		start = 1;
		fl(i,0,N)
		{
			if(arr[i] != start)
				isPossible = 0;

			if(i%2 == 1)
				start += 2;
		}
	}
	else
	{
		start = 0;
		if(arr[0] != 0)
			isPossible = 0;
		start = 2;
		fl(i,1,N)
		{
			if(arr[i] != start)
				isPossible = 0;

			if(i % 2 == 0)
				start += 2;
		}
	}

	if(isPossible)
		printf("%lld\n", modPow(2LL,(N / 2)*1LL));
	else
		printf("0\n");


	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

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

    int r;
    cin >> r;
    
    string m = "";
    if(r < 1200) m = "ABC";
    else if(r < 2800) m = "ARC";
    else m = "AGC";

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>

int main(){
    char ch;
    while (1){
        scanf("%c",&ch);
        
        if (islower(ch)){//小文字なら大文字に変換
            printf("%c",toupper(ch)); 
        } else if (isupper(ch)){//大文字なら小文字に変換
            printf("%c",tolower(ch));
        } else {
            printf("%c",ch);
        }

        if ( ch == '\n'){
            break;
        }
    }

    return 0;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,maxl=0,minr=2147483647;
    cin>>n>>m;
    int l[m],r[m];
    for(i=0;i<m;i++)
	{
        cin>>l[i]>>r[i];
        maxl=max(maxl,l[i]);
        minr=min(minr,r[i]);
    }
    cout<<max(minr-maxl+1,0);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

int main(){
	
	int n,m;
	cin>>n>>m;
	
	vector<int> x(n),y(m);
	
	for(int i=0;i<n;i++){
		cin>>x[i];
	}
	
	for(int i=0;i<m;i++){
		cin>>y[i];
	}
	
	vector<int> dif_x(n-1),dif_y(m-1);
	
	for(int i=0;i<n-1;i++){
		dif_x[i] = x[i+1] - x[i];
	}
	
	for(int i=0;i<m-1;i++){
		dif_y[i] = y[i+1] - y[i];
	}
	
	int width = 0;
	
	for(int i=0;i<n-1;i++){
		int a = i+1;
		int b = n-1-i;
		int c = mod(dif_x[i]*mod(a*b));
		width = mod(width + c);
	}
	
	int height = 0;
	for(int i=0;i<m-1;i++){
		int a = i+1;
		int b = m-1-i;
		int c = mod(dif_y[i] * mod(a*b));
		height = mod(height + c);
	}
	
	cout<<mod(width * height)<<endl;
	
    return 0;
}



Measured memory_bytes: 1792
//  s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま
//  s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま
//s配列に格納した単語を、辞書順にソートする
//getline(cin, s);
//  sort(s.begin(), s.end());
//  string t = "keyence";//で文字列入力ができる
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
int kan_hyaku(int n){
  int kurai = 0;
  for(int i=0;i<3;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ju(int n){
  int kurai = 0;
  for(int i=0;i<2;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ichi(int n){
  int kurai = 0;
  for(int i=0;i<1;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int main() {
  ll n;
  cin >> n;
  vector<ll>a(n);
  rep(i,n) cin>>a.at(i);
  map<ll,ll>mp;
  rep(i,n){
    mp[a.at(i)]++;
  }
  ll one  = 0;
  ll two = 0;
  for(auto p:mp){
//    cout << p.first << " " << p.second << endl;
    if(p.second >= 2){
      if(one <= p.first){
        two = one;
        one = p.first;
      }
    }
    if(p.second >= 4){
      if(one <= p.first){
        two = p.first;
        one = p.first;
      }
    }
  }
//  cout << one << endl;
//  cout << two << endl;
//  cout << endl;
  cout << one * two << endl;
}


Measured memory_bytes: 10224
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- 整数の入力
    len <- readLn
    -- スペース区切り整数の入力
    as <- map strToInt . words <$> getLine
    let os = map (show . fst) $ filter (\(x, y) -> odd  y) $ zip as [1..len]
    let es = map (show . fst) $ filter (\(x, y) -> even y) $ zip as [1..len]
    if len == 1 then print $ head as
        else if even len then putStrLn $ (unwords $ reverse $ es) ++ " " ++ (unwords os)
                else putStrLn $ (unwords $ reverse os) ++ " " ++ (unwords es)



Measured memory_bytes: 154108
import sys
input = sys.stdin.readline

n, a, b, c = [int(x) for x in input().split()]
score = {}
score["A"] = a
score["B"] = b
score["C"] = c     
S = [input().rstrip() for _ in range(n)]
ans = []

for i in range(n - 1):
    s = S[i]
    next_s = S[i + 1]
    s1 = s[0]
    s2 = s[1]
    if score[s1] == 0 and score[s2] == 0:
        print("No")
        sys.exit()
    elif score[s1] == 0:
        ans.append(s1)
        score[s1] += 1
        score[s2] -= 1
    elif score[s2] == 0:
        ans.append(s2)
        score[s1] -= 1
        score[s2] += 1
    else:
        if next_s == s:
            ans.append(s1)
            score[s1] += 1
            score[s2] -= 1
        elif s1 in next_s:
            ans.append(s1)
            score[s1] += 1
            score[s2] -= 1
        else:
            ans.append(s2)
            score[s2] += 1
            score[s1] -= 1
s = S[-1]
s1 = s[0]
s2 = s[1]

if score[s1] == 0 and score[s2] == 0:
        print("No")
        sys.exit()
elif score[s1] == 0:
    ans.append(s1)
    score[s1] += 1
    score[s2] -= 1
elif score[s2] == 0:
    ans.append(s2)
    score[s1] -= 1
    score[s2] += 1
else:
    ans.append(s1)
print("Yes")
for i in ans:
    print(i)






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

int main(){
  string X;
  cin >> X;
  
  int removed_count = 0, left_count = 0;

  for(int i = 0; i < X.length(); i++){
    if(X[i] == 'S'){
      left_count++;
    }else{
      if(left_count > 0){
	left_count--;
	removed_count += 2;
      }
    }
  }

  cout << X.length() - removed_count << endl;
}


Measured memory_bytes: 832
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main() {
	int a, b;
	cin >> b;
	a = b % 10;
	if ((a == 2) || (a == 4) || (a == 5) || (a == 7) || (a == 9)) {
		cout << "hon";
	}
	else if (a == 3) {
		cout << "bon";
	}
	else {
		cout << "pon";
	}
	return 0;
}

Measured memory_bytes: 3592
package main

import (
	"fmt"
	"sort"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

type P struct {
	l, r int
}

func main() {
	var N int
	fmt.Scanf("%d\n", &N)

	P := make([]int, N)
	for i := 0; i < N; i++ {
		var n int
		fmt.Scan(&n)
		P[i] = n
	}
	sort.Ints(P)
	piv := N / 2

	fmt.Println(P[piv] - P[piv-1])
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    char C1,C2;
    string s;

    cin >> x[0] >> x[1] >> x[2];

    sort(x,x+3);

    if(x[0]==5 &&x[1]==5 &&x[2]==7) cout << "YES"; 
    else cout << "NO";

    return 0;
}

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

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll pwr(ll a, ll b){
    if(b==0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b==0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
/*
void Dfs(int u, int p){
    visited[u] = 1;
    if(a[u]) con[u] = con[p] + 1;
    else con[u] = 0;
    if(con[u] > mx[p]) mx[u] = con[u];
    else mx[u] = mx[p];

    for(int i : adj[u]){
        if(i != p){
            Dfs(i, u);
        }
    }
}
*/
int dsum(int x){
    if(x == 0) return 0;
    return ( (x%10) + dsum(x/10));
}
int main(){
	int n;
	cin >> n;
	int a[n], b[n];
	int mx = INT_MIN, mx2 = INT_MIN;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	mx = b[n - 1];
	mx2 = b[n - 2];
	
	for(int i = 0; i < n; i++){
		if(a[i] == mx) cout << mx2;
		else cout << mx;
		cout << " ";
	}
	
}



Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
    int64_t N, A;
    cin >> N >> A;
    for (int i=0;i<4;++i) {
        int64_t x;
        cin >> x;
        if (x < A) A = x;
    }

    cout << (N + A - 1) / A + 4 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define INFTY 1000000000

int count = 0;

void merge(int A[], int left, int mid,int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1 + 1],R[n2 + 1];
	int i,j,k;
	for(i = 0; i < n1; i++){
		L[i] = A[left + i];
	}
	for(i = 0; i < n2; i++){
		R[i] = A[mid + i];
	}
	L[n1] = INFTY;
	R[n2] = INFTY;
	i = 0;
	j = 0;
	for(k = left; k < right; k++, count++){
		if(L[i] <= R[j]){
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(int A[], int left, int right){
	if(left + 1 < right){
		int mid = (left + right)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}

int main(void){
	int n,i;
	scanf("%d",&n);
	int S[n];
	for(i = 0; i < n;i ++){
		scanf("%d",&S[i]);
	}
	mergeSort(S,0,n); 
	for(i = 0; i < n; i++){
		printf("%d",S[i]);
		if(i < n -1){
			printf(" ");
		}
	}
	printf("\n%d\n",count);
	return 0;
}




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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

int r,g,b,n;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> r >> g >> b >> n;

  ll res = 0;
  for (int i = 0; i*r <= n; i++) {
    for (int j = 0; j*g + i*r <= n; j++ ) {
      if ((n-j*g-i*r)%b == 0) res++;
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> p(n),c(n);
	rep(i, n){
		cin >> p[i];
		p[i]--;
	}
	rep(i, n) cin >> c[i];

	ll ans = -Inf;
	rep(si,n){
		int x = si;
		ll total = 0;
		vector<int> s;
		while (1)
		{
			x = p[x];
			s.push_back(c[x]);
			total += c[x];
			if (x == si)
				break;
		}
		int l = s.size();
		ll t = 0;
		rep(i,l){
			t += s[i];
			if (i + 1 > k)
				break;
			ll now = t;
			if (total > 0){
				ll e = (k - i - 1) / l;
				now += total * e;
			}
			ans = max(ans, now);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    int max = -1 ;
    for(int i = 0; i < N - 1; i++)
    {
        for(int j = i + 1; j < N; j++)
        {
            if(max < abs(A.at(i) - A.at(j)))
            {
                max = abs(A.at(i) - A.at(j));
            }
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
#define size 105
char map[size][size];
bool row[size];
bool col[size];
//TODO:
int main()
{
    ios::sync_with_stdio(false);
    int h,w;
    while(cin>>h>>w)
    {
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                cin>>map[i][j];
            }
        }
        memset(row,0,sizeof(row));
        memset(col,0,sizeof(col));
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                if(map[i][j]=='#')
                {
                    row[i]=true;
                    col[j]=true;
                }
            }
        }
        for(int i=0;i<h;i++)
        {
            if(row[i])
            {
                for(int j=0;j<w;j++)
                {
                    if(col[j])
                    {
                       cout<<map[i][j];
                    }
                }
                cout<<endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[300000];
  int ans=0;
  rep(i,3*n) cin>>a[i];
  sort(a,a+(3*n),greater<int>() );
  for(int i=1;i<(2*n);i+=2){
    ans+=a[i];
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


vector<vector<int>>A;
int H, W, D;


P find(int n) {
	rep(i, H)rep(j, W) {
		if (A[i][j] == n) {
			return { i,j };
		}
	}
}


signed main() {
	cin >> H >> W >> D;
	A.resize(H);
	rep(i, H)A[i].resize(W);
	rep(i, H)rep(j, W)cin >> A[i][j];
	vector<int>d(H * W + 1);
	P now, next;
	for (int i = 1; i <= D; i++) {
		for (int j = i; j <= H * W; j += D) {
			if (j == i) {
				d[j] = 0;
				now = find(j);
			}
			else {
				next = find(j);
				d[j] = d[j - D] + abs(next.first - now.first) + abs(next.second - now.second);
				now = next;
			}
		}
	}

	int Q;
	cin >> Q;
	vector<int>ans(Q);
	rep(i, Q) {
		int L, R;
		cin >> L >> R;
		ans[i] = d[R] - d[L];
	}
	rep(i, Q)cout << ans[i] << endl;
}

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

int n,m;
int p(int m){
  int ret = 1;
  for(int i=0;i<m;i++) ret *= 2;
  return ret;
}
int main(){
  cin >> n >> m;
  int ans = 0;
  for(int i=0;i<p(m);i++){
    ans += 1900*m + 100*(n-m);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val h, w = sc.nextInt
    val m = Array.fill(h, w)(0)
    for (i <- 0 until h; j <- 0 until w) {
      m(i)(j) = sc.nextInt
    }

    // 下右 だけでいいのかな。。。
    val DI = Array(1, 0)
    val DJ = Array(0, 1)

    var operations = new ArrayBuffer[String]()
    for (i <- 0 until h; j <- 0 until w) {
      val n = m(i)(j)
      if (n % 2 != 0) {
        // 奇数だったら配る
        var delivered = false
        var dIndex = 0
        while (!delivered && dIndex < 2) {
          val ni = i + DI(dIndex)
          val nj = j + DJ(dIndex)
          if (ni >= 0 && ni < h && nj >= 0 && nj < w) {
            val nn = m(ni)(nj)
            operations += s"${i + 1} ${j + 1} ${ni + 1} ${nj + 1}"

            m(i)(j) -= 1
            m(ni)(nj) += 1

            delivered = true
          }
          dIndex += 1
        }
      }
    }

    val pw = new java.io.PrintWriter(System.out)
    pw.println(operations.size)
    for (operation <- operations) {
      pw.println(operation)
    }
    pw.flush()
  }
}


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

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

int N;
vi A, B, C;
ll dp[100100] = {}; // dp[i] = Biより大きいCiの個数
ll ans = 0;

void solve() {
    cin >> N;
    A.resize(N);
    B.resize(N);
    C.resize(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    for (int i = N-1; i >= 0; --i) {
        auto it = lower_bound(C.begin(), C.end(), B[i]+1);
        dp[i] = N - (it - C.begin());
        if (i < N-1) dp[i] += dp[i+1];
    }
    rep(i,N) {
        auto it = lower_bound(B.begin(), B.end(), A[i]+1);
        ans += dp[it-B.begin()];
    }
    cout << ans << endl;
}

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

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> X(N);
    rep(i, N) cin >> X[i];

    vector<vector<ll>> cnt(M);
    rep(i, N){
        cnt[X[i]%M].push_back(X[i]);
    }
    ll ans = 0;
    ans += cnt[0].size() / 2;
    if (M % 2 == 0) ans += cnt[M / 2].size() / 2;
    rep(i, (M -1) / 2) {
        ll idx = i + 1;
        ll jdx = M - i - 1;
        if (cnt[idx].size() > cnt[jdx].size()) swap(idx, jdx);
        vector<ll> T = cnt[jdx];
        vector<ll> S = cnt[idx];

        map<ll, ll> mp;
        rep(j, cnt[jdx].size()){
            mp[cnt[jdx][j]]++;
        }
        ll tmp = 0;
        for(auto x:mp){
            tmp += x.second/2;
        }
        ans += (int)cnt[idx].size();
        ll sa = (int)cnt[jdx].size() - (int)cnt[idx].size();
        ans += min(sa/2, tmp);
    }
    cout << ans << '\n';
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  map<LL, LL> m;
  int N, M; cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    LL A, B; cin >> A >> B;
    m[A] += B;
  }

  LL cost = 0;
  for (auto [a, b] : m) {
    if (M >= b) {
      M -= b;
      cost += a * b;
    } else {
      cost += a * M;
      break;
    }
  }
  cout << cost << endl;
}


Measured memory_bytes: 9864
#!/bin/sh
read
cnt=0
for i in `echo $REPLY | awk '{for(i=1;i<=NF;i++)print $i}' | sort -n`
do
	cnt=$(( cnt + 1 ))
	eval n$cnt=$i
done
n=$(( $(( $(( n1 % 2 )) + $(( n2 % 2 )) + $(( n3 % 2 )) )) % 2 ))
if [ $n -eq 1 ]
then
	echo $(( n1 * n2 ))
else
	echo 0
fi


Measured memory_bytes: 1224
M = 10**9+7
import sys
input = sys.stdin.readline
def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    A_ = sorted(A, reverse = True)
    ans = 0
    ans_ = 0
    for i in range(0,N-1):
        for j in range(i+1,N):
            if A[i] > A[j]:
                ans += 1
            if A_[i] > A_[j]:
                ans_ += 1

    print(int((((K*(K-1)//2)%M)*ans_+ans*K)%M))

if __name__ == '__main__':
    main()

Measured memory_bytes: 39920
#include<stdio.h>

int main()
{
	long int d,j;
	long int sum=0;

	while(scanf("%ld",&d) != EOF)
	{
		if(600%d!=0)
			continue;
		sum=0;
		j=d;
		while(j<=600-d)
		{
			sum+=d*j*j;
			j+=d;
		}
	
		printf("%ld\n",sum);
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<cmath>
#include<functional>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
//#include<bits/stdc++.h>
using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	auto f0 = a+b;
	auto f1 = a-b;
	auto f2 = a*b;
	
	cout << max(f0,max(f1,f2));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000




int main(){
    
	int N;
	cin>>N;
	
	long long K;
	cin>>K;
	
	vector<long long> A(N),F(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	for(int i=0;i<N;i++){
		cin>>F[i];
	}
	
	sort(A.begin(),A.end());
	sort(F.begin(),F.end(),greater<long long> ());
	
	long long ok = Inf;
	long long ng = -1;
	while(ok-ng>1){
		long long mid = (ok+ng)/2;
		long long cnt = 0;
		for(int i=0;i<N;i++){
			long long a = A[i]*F[i]-mid;
			long long b = (a + F[i]-1)/F[i];
			if(b>=0)cnt += b;
		}
		if(cnt>K)ng=mid;
		else ok=mid;
	}
	
	cout<<ok<<endl;
	
    return 0;
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  reverse(all(a));
  ll ans = 0;
  
  for (int i = 1; i < n;i++){
    ans += a[i/2];
  }
  cout << ans << endl;
  return 0;
}


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

using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
    LL N;
    cin >> N;
    int ans = 1 + (N > 2);
    for(int i = 2; LL(i)*i <= N; i++){
        if(N%i == 0){
            LL m = N;
            while(m%i == 0){
                m /= i;
            }
            m %= i;
            if(m == 1) ans++;
            if(N/i != i){
                int j = N/i;
                m = N;
                while(m%j == 0) m /= j;
                m %= j;
                if(m == 1) ans++;
            }
        }
    }
    for(int i = 2; LL(i)*i <= N-1; i++){
        if((N-1)%i == 0){
            ans++;
            if((N-1)/i != i){
                ans++;
            }
        }
    }
    cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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 main(){
    ll n;cin >> n;
    vector<double> p(n);rep(i,n)cin >> p[i];
    vector<vector<double>> dp(n+1,vector<double>(n+2));
    dp[0][0]=1;
    rep(i,n){
        rep(j,n+1){
            dp[i+1][j+1]+=p[i]*dp[i][j];
            dp[i+1][j]+=-(p[i]-1)*dp[i][j];
        }
    }
    double ans=0;
    rep(i,n+1){
        if(i>n/2)ans+=dp[n][i];
    }
    CST(12);
    cout << ans <<endl;
}

Measured memory_bytes: 73776
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    for(int idx = 0; idx < s.size(); idx += 2) cout << s[idx];
    cout << endl;
}

Measured memory_bytes: 512