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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 1000007, inf = 0x3f3f3f3f;

int a[N];
int main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int n, k; cin >> n >> k;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a, a + n);
	ll sum = 0;
	for(int i = 0; i < k; i++) {
		sum += a[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();

        int divided = -1;

        int[] fromleft_GCD = new int[N];
        int[] fromright_GCD = new int[N];

        fromleft_GCD[0] = A[0];
        fromright_GCD[N-1] = A[N - 1];
        for (int i = 1; i < N; i++)
        {
            fromleft_GCD[i] = gcd2(fromleft_GCD[i - 1], A[i]);
            fromright_GCD[N-i-1] = gcd2(fromright_GCD[N-i], A[N - i - 1]);

        }
        int max_gcd = Math.Max(fromleft_GCD[N - 2],fromright_GCD[1]);
        for (int i = 0;i <N-2;i++)
        {
            var temp = gcd2(fromleft_GCD[i], fromright_GCD[i + 2]);
            if (max_gcd < temp) max_gcd = temp;


        }
        Console.WriteLine(max_gcd);

    }



    public static int[] prime_109()
    {
        List<int> numbers = new List<int>();
        for (int i = 2; i < 100000; i++)
        {
            numbers.Add(i);
        }
        List<int> output = new List<int>();
        while (numbers.Count != 0)
        {
            int temp = numbers[0];
            numbers.RemoveAt(0);
            output.Add(temp);
            var d =numbers.Where(x => x % temp != 0);
            numbers = new List<int>(d);
        }
        return output.ToArray();

    }


    public static int gcd2(int a, int b)
    {
        if (a % b == 0) return b;
        else return gcd2(b, a % b);

    }


}

Measured memory_bytes: 31068
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, c, k = map(int, readline().split())
t = [int(readline()) for _ in range(n)]
t.sort()
ans = 1
tmp = [t[0], 0]
for tt in t:
    if tmp[0] + k < tt or tmp[1] + 1 > c:
        ans += 1
        tmp = [tt, 0]
    tmp[1] += 1
print(ans)


Measured memory_bytes: 7380
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;

int f(int d, vector<int> &s, int q)
{
	if( s.back()<=q){
		return min(q-s.back(),d-q);
	}

	int x=0;
	int y=s.size()-1;
	while(x<=y){
		int h= (x+y)/2;
		if(s[h]==q) return 0;
		if(s[h]<q){
			x=h+1;
		}else{
			y=h-1;
		}
	}
	int mind=d;
	for(int i=max(x-1,0);i<=min(x+1,d-1);i++){
		int dd = abs(q-s[i]);
		if(dd>d-dd) dd=d-dd;
		if(dd<mind) mind=dd;
	}
	return mind;
}	

int main() {
	int d,n,m,q;
	istream &sin=cin;
	ostream &sout=cout;
//	fstream sin("input.txt",fstream::in);
//	fstream sout("output.txt",fstream::out);

	while(true){
	sin >> d >> n >> m;
	if(d==0)break;
	
	vector<int> s(n);
	for(int i=1;i<n;i++){
		sin >> s[i];
	}
	sort(s.begin(),s.end());
	int ans=0;
	for(int i=0;i<m;i++){
		sin >> q;
		int mind = f(d,s,q);
/*		int mind=d;
		for(int j=0;j<n;j++){
			int dd = abs(s[j]-q);
			if(dd*2>d) dd=d-dd;
			if(dd<mind){
				mind=dd;
			}
		}
		sout << mind << endl;
*/		ans+=mind;
	}
	sout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1524
#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int N = 1e5+4;
int a[N],b[N];
vector <int> v;
map <int,bool> m;
map <int,bool> m1;
int n;
signed main()
{
	ll s1 = 0,s2 = 0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i],&b[i]);
		s1 += a[i],
		s2 += b[i];

		v.push_back(a[i]);
		v.push_back(b[i]);
	}

	sort(v.begin(),v.end());
	ll S = 0,ans = min(s1,s2);
	// cout<<s1<<' '<<s2<<'\n';

	for(int i=0;i<n-2;i++)
	{
		// cout<<v[i]<<' ';
		S += v[i];
		m[v[i]] = true;
	}
	// cout<<S<<'\n';
	for(int i=1;i<=n;i++)
	{
		ll res = S + a[i] + b[i];
		m1[a[i]] = true;
		m1[b[i]] = true;
		int cnt = 0;
		if(m[a[i]] == true)
			res -= a[i],
			cnt++;

		if(m[b[i]] == true)
			res -= b[i],
			cnt++;


		if(cnt == 1)
		{
			if(m1[v[n-2]] == true)
				res += v[n-1];

			else
				res += v[n-2];
		}
		else if(cnt == 2)
			res += (v[n-2] + v[n-1]);

		ans = min(ans,res);
		m1[a[i]] = false;
		m1[b[i]] = false;

	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 28400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(b - a == c - b) out("YES");
    else out("NO");
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
ll n,m,u1,u2;
ll b[5001];
struct P{
	ll pos,time;
};
P a[5001];
vector<ll>e[5001];
bool operator<(P a,P b){return a.time<b.time;}
int main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		a[i]=P{i,-1};
		b[i]=0;
	}
	for(ll i=0;i<m;i++){
		cin>>u1>>u2;
		e[u1].push_back(u2);
		b[u2]++;
	}
	queue<ll>p;
	for(ll i=1;i<=n;i++){
		if(b[i]==0){
			p.push(i);
			a[i].time=0;
		}
	}
	while(!p.empty()){
		ll t=p.front();p.pop();
		for(ll i=0;i<e[t].size();i++){
			if(a[e[t][i]].time<a[t].time+1){
				a[e[t][i]].time=a[t].time+1;
				p.push(e[t][i]);
			}
		}
	}
	sort(a+1,a+n+1);
	for(ll i=1;i<=n;i++){
		cout<<a[i].pos<<endl;
	}
	int sum=0;
	for(ll i=1;i<=n;i){
		int sum2=0,j=i;
		while(a[j].time==a[i].time&&j<=n){
			sum2++;
			j++;
		}
		i=j;
		sum=max(sum,sum2);
	}
	if(sum>1)
	cout<<1<<endl;
	else cout<<0<<endl;
}

Measured memory_bytes: 4668
def dfs_visit(u):
    global dfs_color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] = BLACK
    f[u] += t
    t += 1

n = int(input())
M = [[False for i in range(n)] for j in range(n)]
WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
t = 1
for i in range(n):
        a = list(map(int, input().split()))
        for j in range(a[1]):
            M[a[0] - 1][a[j + 2] - 1] = True
for u in range(n):
    if color[u] == WHITE:
        dfs_visit(u)
for u in range(n):
    print(str(u + 1), str(d[u]), str(f[u]), sep = " ")

Measured memory_bytes: 5808
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)

def lcm(a,b):
  return a * b // gcd(a,b)

n = int(input())
av = list(map(int, input().split(' ')))
alcm = 1
for i in av:
  alcm = lcm(alcm, i)

tot = 0
for i in range(n):
  tot += alcm // av[i]

print(tot % 1000000007)

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

int main() {
  int n, m; cin >> n >> m;
  multimap<int, int> paths;
  while (m--) {
    int first, second; cin >> first >> second;
    paths.insert(make_pair(first, second));
    paths.insert(make_pair(second, first));
  }
  
  vector<int> apexes(n);
  for (int i = 0; i < n; i++) apexes.at(i) = i + 1;
  
  int answer = 0;
  do {
    if (apexes.at(0) != 1) break;
    
    for (int i = 0; i < n - 1; i++) {
      auto range = paths.equal_range(apexes.at(i));
      
      bool valid = false;
      while (range.first != range.second) {
        if (apexes.at(i + 1) == range.first -> second) {
          valid = true;
          break;
        }
        range.first++;
      }
      
      if (!valid) break;
      if (i == n - 2) answer++;
    }
  } while (next_permutation(apexes.begin(), apexes.end()));
  
  cout << answer << endl;
}

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

int main() {
    ll A;
    cin >> A;
    string B;
    cin >> B;

    bool flag = false;
    int count = 0;

    ll Bdash = 0;

    for(int i = 0; i < B.size(); i++) {
        if(B[i] == '.') {
            flag = true;
        } else {
            Bdash = Bdash * 10 + (ll)(B[i] - '0');
            if(flag) {
                count++;
            }
        }
    }

    ll ans = A * Bdash;
    for(int i = 0; i < count; i++) {
        ans /= 10;
    }

    cout << ans << endl;
}

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

int main() {
    using namespace std;
    unsigned long X;
    cin >> X;
    vector<unsigned long> dp(X + 1);
    dp[0] = 1;
    for(unsigned long i = 100; i <= 105; ++i){
        for(unsigned long j = 0; j + i <= X; ++j){
            dp[j + i] |= dp[j];
        }
    }
    cout << dp.back() << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { //Modular inverse of a is a^(mod-2)%mod
		Scanner input = new Scanner(System.in);
		long X = input.nextLong();
		long Y = input.nextLong();
		long ans = 0;
		long mod = (long)(1e9+7);
		long[] fact = new long[1000001]; //[Factorial,Inverse]
		fact[1]=1;
		for (long i = 2; i <= 1000000; i++) {
			fact[(int) i]=fact[(int) (i-1)]*i;
			fact[(int) i]%=mod;
		}
		if ((X+Y)%3==0) {
			long min = Math.min(X, Y);
			long max = Math.max(X, Y);
			if (max<=min*2) {
				if (max==min*2) ans=1;
				else {
					long diff = max-min;
					long sub = min-diff;
					long totalMoves = sub/3; //Each move increases sum of coordinates by 3
					totalMoves*=2; //Each move alters x AND y though so need to 
					//multiply by 2 to avoid WA
					max-=sub;
					min-=sub;
					totalMoves+=min;
					long chooseOptions = sub/3;//(3,3) requires one of each knight move
					long inv1 = FastExp(fact[(int) chooseOptions],mod-2,mod);
					long inv2 = FastExp(fact[(int) (totalMoves-chooseOptions)],mod-2,mod);
					ans=fact[(int) totalMoves];
					ans*=inv1;
					ans%=mod;
					ans*=inv2;
					ans%=mod;
				}
			}
		}
		System.out.println(ans);
	}	
	public static long FastExp(long base, long exp, long mod) {
		long ans = 1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			base*=base;
			exp/=2;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
}

Measured memory_bytes: 31828
import sys
from bisect import bisect_left, bisect_right, insort

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
S = list('-' + sr())
d = [[] for _ in range(26)]
for i in range(1, N+1):
    s = S[i]
    o = ord(s) - ord('a')
    d[o].append(i)

Q = ir()
for _ in range(Q):
    q, a, b = sr().split()
    if q == '1':
        a = int(a)
        if S[a] == b:
            continue
        prev = ord(S[a]) - ord('a')
        d[prev].pop(bisect_left(d[prev], a))
        next = ord(b) - ord('a')
        insort(d[next], a)
        S[a] = b
    else:
        left = int(a); right = int(b)
        ans = 0
        for alpha in range(26):
            index = bisect_left(d[alpha], left)
            if index < len(d[alpha]) and d[alpha][index] <= right:
                ans += 1
        print(ans)


Measured memory_bytes: 30984
#include <bits/stdc++.h>
using namespace std;
int keta(long long int k){
   int ans=1;
	while(true){
    	if(k/10==0) return ans;
      	else {
        	ans++;
          	k/=10;
        }
    }
}

int main() {
  long long int n;cin>>n;
  int ans=20;
  for(long long int i=1;i*i<=n;i++){
  	if(n%i==0){
    	ans=min(ans,max(keta(i),keta(n/i)));
    }
  }
  cout<<ans<<endl;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll a,b,c;
	cin >>a >>b >>c;
	
	if(c-a-b <0){puts("No"); return 0;}
	if(4*a*b < (c-a-b)*(c-a-b)) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
a_s = input()
b_s = input()
if a_s == b_s:
    print('EQUAL')
elif len(a_s) > len(b_s):
    print('GREATER')
elif len(a_s) < len(b_s):
    print('LESS')
else:
    a = list(map(int, list(a_s)))
    b = list(map(int, list(b_s)))
    for ai, bi in zip(a, b):
        if ai > bi:
            print('GREATER')
            break
        elif ai < bi:
            print('LESS')
            break


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int N, K, R, S, P;
int katu(char c){
if(c=='r'){ return P; }
if(c=='s'){ return R; }
if(c=='p'){ return S; }
}
int main(){
int ans=0, i, j; string T; cin >> N >> K >> R >> S >> P >> T;
string U=string(N,'.');
for(i=N-1; i>=0; i--){ 
  if(U[i]!='.'){ break; }
  for(j=i; j>=0; j-=K){
     if(j+K<=i){ if(T[j+K]==T[j]){ U[j]=(U[j+K]=='k')?'m':'k'; }else{ U[j]='k'; } }
     else{ U[j]='k'; }
  }
}  
for(i=0; i<N; i++){ if(U[i]=='k'){ ans+=katu(T[i]); } } 
cout << ans << "\n";
}

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

int main(){
  long long n, k;
  cin >> n >> k;
  
  long long cnt = n / k;
  long long cnts = (n + k / 2) / k;
  
  long long ans = pow(cnt, 3);
  if(k%2 == 0) ans += pow(cnts, 3);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long M =2e5+2,MOD=1e9+7;
typedef long long ll;
#define pb push_back
#define Y printf("YES\n")
#define N printf("NO\n")
#define O printf("-1\n")
bool f_2=false,vis[M]= {false},f=false;
vector<ll>v[M],v_1,v_2;
string s,p,q,ok,ch;
map<ll,ll>mp,mp_2;
set<ll>st,st_1;
ll parent[M],subtree[M]={0},cont[M]={0};
ll cnt=0,cost=0,mx=0,NODE,t,par,zero=0,pos=0,neg=0;
//deque<ll>Q;
//vector< pair<ll,ll > >v,v_1;
struct node
{
    ll pa,ran,visit;

};
//node X[M];
void bfs()
{
    for(ll i=0;i<M;i++)
    {
        parent[i]=i;
    }
    queue<ll>Q;
    Q.push(1);
    cont[1]=subtree[1];
    while(!Q.empty())
    {
        ll a=Q.front();
        //cout<<a<<endl;
        Q.pop();
        vis[a]=true;
        for(ll i=0;i<v[a].size();i++)
        {
            ll b=v[a][i];
           // cout<<a<<" "<<b<<endl;
            if(!vis[b])
            {
                Q.push(b);
                cont[b]+=subtree[b]+cont[a];
                vis[b]=true;
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);//ISHWAR
    cin.tie(0);//Tourist_Twin
    //freopen("kamona.txt","r",stdin);
    ll a,b,c,n,t,sum=0,mx=0,l,x,y,i=0,j=0,res,m,second=0,d;
    cin>>n>>t;
    for(i=0;i<n-1;i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    for(i=0;i<t;i++)
    {
        cin>>x>>y;
        subtree[x]+=y;
    }
    bfs();
    for(i=1;i<=n;i++)
        cout<<cont[i]<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 20720
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	set<string> group;
	int N;
	cin >> N;
	rep(i, N) {
		string s;
		cin >> s;
		group.emplace(s);
	}

	printf("%d\n", group.size());


EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 15664
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<#x<<'='<<x<<endl
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}


void solve()
{

	ll i=0,j=0,k=0,m,n,p,q,sum=0,cnt=0;
	cin>>n>>m>>k;
	ll a[n];
	ll b[m];
	for(i=0;i<n;i++)
	cin>>a[i];
	
	for(i=0;i<m;i++)
	cin>>b[i];

	for(i=1;i<n;i++)
	a[i]+=a[i-1];
	
	for(i=1;i<m;i++)
	b[i]+=b[i-1];
	i=0;j=0;
	p=0;q=0;
	while(a[i]<=k and i<n)
	{
	    p++;
	    i++;
	}
	while(b[j]<=k and j<m)
	{
	    q++;
	    j++;
	}
	p=max(p,q);
	i=0;
	j=m-1;
	while(j>=0 and i<n)
	{
	    while(a[i]+b[j]>k and j>0)
	    {
	        j--;
	    }
	    if(a[i]+b[j]<=k)
	    {
	        cnt=max(cnt,i+j+2);
	        
	    }
	    i++;
	}
	cout<<max(p,cnt);
	
	
	
	
	
}
int main() {
    fast
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w+", stdout);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 6772
#include <iostream>
using namespace std;
int main(){
    int S,h,m,s;
    cin >> S;
    if (S>=0 && S<=86400) {
        s = S%60;
        m = S/60%60;
        h = S/60/60;
        cout << h << ":" << m << ":" << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int cnt = 0;
        for (int i = a ; i<=b;i++){
            if (c%i==0){
                cnt ++;
            }
        }
        System.out.println(cnt);
    }
}



Measured memory_bytes: 26328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
 
 
#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>
 
using namespace std;

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,a;
    vector<int> row,s;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a;
        row.push_back(a);
        s.push_back(a);
    }
    VSORT(s);
    int  count  = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] != row[i]){
            count++;
        }
    }
    if(count == 2 || count == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

using P = pair<int, int>;
#define fi first
#define se second


P check_lr(string &s) {
    int n = s.size();
    P ans;
    int left = 0, right = 0;
    for (int i=0; i<n; i++) {
        if (s[i] == '(') left++;
        if (s[i] == ')' && right < left) right++;
    }
    ans.se = left - right;
    left = 0, right = 0;
    for (int i=n-1; i>=0; i--) {
        if (s[i] == ')') right++;
        if (s[i] == '(' && left < right) left++;
    }
    ans.fi = right - left;
    return ans;
}

int main() {
    int n;
    cin >> n;
    vector<P> lrs;
    P left_edge = {0, 0}, right_edge = {0, 0};
    int dif = 0, complete = 0;
    for (int i=0; i<n; i++) {
        string s; cin >> s;
        P lr = check_lr(s);
        lrs.push_back(lr);
    }
    sort(lrs.begin(), lrs.end(), [](P a, P b) {
        if (a.fi - a.se >= 0 && b.fi - b.se < 0) return false;
        else if (a.fi - a.se < 0 && b.fi - b.se >= 0) return true;
        else if (a.fi - a.se < 0 && b.fi - b.se < 0) {
            return a.fi < b.fi;
        } else {
            return a.se > b.se;
        }
    });
    int match = 0;
    for (auto &lri:lrs) {
        if  (match < lri.fi) {
            cout << "No" << '\n';
            return 0;
        }
        match -= lri.fi;
        match += lri.se;
    }
    cout << (match == 0 ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 11644
#define ll long long
m;b;l;ll i;
ll r;
int p(ll*a,ll*b){return *a-*b;}
main(n){
    scanf("%d",&n);scanf("%d",&m);
    int a[n+1];
    for (l=n,a[0]=0;n>0&&scanf("%d",&b);--n)a[l-n+1]=(b+a[l-n])%m;
    qsort(a,l+1,4,p);
    for (i=1,n=0;n<l;++n){while (n<l&&a[n+1]==a[n]){++i;++n;}r+=i*(i-1)/2;i=1;}
    printf("%lld",r);
}

Measured memory_bytes: 892
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int dx[]={1,0};
		int dy[]={0,1};
		while(in.hasNext())
		{
			int H=in.nextInt();
			int W=in.nextInt();
			int cost[][]=new int[H][W];
			int map[][]=new int[H][W];
			LinkedList<String>que=new LinkedList<String>();
			for(int i=0;i<H;i++)
			{
				Arrays.fill(cost[i], 1000);
				String st=in.next();
				for(int j=0;j<W;j++)
					map[i][j]=Integer.valueOf(st.charAt(j)-'0');
			}
			cost[0][0]=0;
			que.add(0+" "+0);
			while(!que.isEmpty())
			{
				int size=que.size();
				for(int i=0;i<size;i++)
				{
					String now[]=que.poll().split(" ");
					int nh=Integer.valueOf(now[0]);
					int nw=Integer.valueOf(now[1]);
					for(int j=0;j<2;j++)
					{
						int h=dy[j]+nh;
						int w=dx[j]+nw;
						if(h<H&&w<W)
						{
							if(cost[h][w]>cost[nh][nw]+map[h][w])
							{
								cost[h][w]=cost[nh][nw]+map[h][w];
								que.add(h+" "+w);
							}
						}
					}
				}
			}
			System.out.println(cost[H-1][W-1]);
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  string s, t;
  cin >> s >> t;
  int a = s.length();
  rep(i,a) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (t.length() != a + 1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
} 


Measured memory_bytes: 3632
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
dict1 = {}
for _ in range(n):
    price, b = map(int, input().split())
    if price in dict1:
        dict1[price] += b
    else:
        dict1[price] = b

money_cnt = 0
for price, b in sorted(dict1.items()):
    if b < m:
        m -= b
        money_cnt += price * b
    else:
        money_cnt += price * m
        break
print(money_cnt)

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

int main(){
    int a,b;
    while (true){
        cin>>a>>b;
        for(int t=0;t<a;t++){
            for(int h=0;h<b;h++){
                if(h!=b-1){
                   if(t==0||h==0){
                       cout<<"#";
                   }else if(t==a-1){
                       cout<<"#";
                   }else{
                       cout<<".";
                   }
                    
                }else{
                    cout<<"#"<<endl;
                }
            
                
            }
            
            
        }
    if(a==0&&b==0){
        break;
    }    
        cout<<endl;
        
    
        
    }
}


Measured memory_bytes: 3084
def main():
    n,k=map(int,input().split())
    p=list(map(int,input().split()))
    kitai=[]
    ans=0
    for i in range(n):
        buf=sum(range(1,p[i]+1))/p[i]
        kitai.append(buf)
        if i<=k-1:
            ans+=buf
    x=ans
    for i in range(k,n):
        x-=kitai[i-k]
        x+=kitai[i]
        if ans<=x:
            ans=x
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 73992
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
char s[N];
int idxR[N], idxL[N], addup[N];
typedef pair<int, char> PII;
stack<PII> stk;
int main() {
	cin >> s;
	for (int i = 0; s[i]; i ++) {
		if (s[i] == 'R') stk.push({i, s[i]});
		else {
			while(stk.size()) {
				auto t = stk.top();
				idxR[t.first] = i - t.first;
				stk.pop();
			}
		}
	}
	int len = strlen(s);
	for (int i = len - 1; i >= 0; i --) {
		if (s[i] == 'L') stk.push({i, s[i]});
		else {
			while(stk.size()) {
				auto t = stk.top();
				idxL[t.first] = t.first - i;
				stk.pop();
			}
		}
	}

	for (int i = 0; s[i]; i ++) {
		if (s[i] == 'R') {
			if (idxR[i] % 2 == 0) addup[i + idxR[i]] ++;
			else addup[i + idxR[i] - 1] ++;
		}
		else {
			if (idxL[i] % 2 == 0) addup[i - idxL[i]] ++;
			else addup[i - idxL[i] + 1] ++;
		}
	}
	
	for (int i = 0; i < len; i ++) cout << addup[i] << " ";
}

Measured memory_bytes: 4956
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> ar = new ArrayList<>();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        ar.add(a);
        ar.add(b);
        ar.add(c);
        Collections.sort(ar);
        if (ar.get(2) == ar.get(0) + ar.get(1)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
x,y,h,w,T;main(n){for(;T=-scanf("%d",&n)*n;printf("%d\n",T*200))for(;n--;T+=x>6?:x+3)scanf("%d%d%d%d",&x,&y,&h,&w),x=fmax((x+y+h-21)/20,w<3?:(w+9)/5);}

Measured memory_bytes: 0
from itertools import product
h, w = map(int, input().split())
S = [input() for _ in range(h)]
L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
for i, j in product(range(h),range(w)):
    l = S[i][j]
    r = S[i][w-1-j]
    u = S[i][j]
    d = S[h-1-i][j]
    if l == ".": L[i][j] = L[i][max(0, j-1)]+1
    if r == ".": R[i][w-1-j] = R[i][min(w-1, w-j)]+1
    if u == ".": U[i][j] = U[max(0, i-1)][j]+1
    if d == ".": D[h-1-i][j] = D[min(h-1, h-i)][j]+1
A = [L[i][j]+R[i][j]+U[i][j]+D[i][j]-3 for i, j in product(range(h), range(w))]
print(max(A))

Measured memory_bytes: 332308
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] sList = s.split("[^(ACGT)]", 0);

        if (sList.length != 0) {
            int[] iList = new int[sList.length];

            for (int i = 0; i < sList.length; i++) {
                iList[i] = sList[i].length();
            }
            Arrays.sort(iList);


            System.out.println(iList[iList.length - 1]);
        } else {
            System.out.println(0);
        }

    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    string s, t; cin >> s >> t;
    int mn = 1e9;
    int n = s.size(), m = t.size();
    for(int i=0; i<n; i++){
        int ed = i + m - 1;
        if(ed == n) break;
        int cnt = 0;
        for(int j=0; j<m; j++) cnt += s[i+j] != t[j];
        mn = min(mn, cnt);
    }
    cout << mn;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE
vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
} 
  

void solve(void)
{
  int N;
  cin>>N;
  auto div = divisor(N);
  int ANS = INF;
  for (auto &&i : div)
  {
    chmin(ANS,i + N/i);
  }
  cout<<ANS-2<<endl;
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define MATMUL(a, b, c)                                                        \
  REP(i, a.size())                                                             \
  REP(j, b[0].size()) REP(k, a[0].size()) c[i][j] += a[i][k] * b[k][j];
#define CLA2(a) REP(i, a.size()) REP(j, a[0].size()) a[i][j] = 0;
#define REV(T) greater<T>()

ll pow_(ll a, ll n) {
  ll x = 1;
  while (n > 0) {
    if (n & 1)
      x = (x * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return x;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  if (A + B >= C)
    cout << B + C << endl;
  else
    cout << A + B + B + 1 << endl;
  return 0;
}


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

using namespace std;

void formatcheck(int begin, int end){
  if((begin >= 1 && begin <= 12) && (end >= 1 && end <= 12))
    cout << "AMBIGUOUS";
  
  if((begin >= 1 && begin <= 12) && (end < 1 || end > 12))
    cout << "MMYY";
  
  if((begin < 1 || begin > 12) && (end >= 1 && end <= 12))
    cout << "YYMM";
  
  if((begin < 1 || begin > 12) && (end < 1 || end > 12))
    cout << "NA";
}

int main(){
  char c[4];
  int begin;
  int end;
  for(int i = 0; i < 4; i++){
    cin >> c[i];
  }
  
  begin = (c[0]-'0') * 10 + c[1]-'0';
  end = (c[2]-'0') * 10 + c[3]-'0';
  formatcheck(begin, end);
  cout << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
	int t1, t2, r1, r2; cin >> t1 >> t2 >> r1 >> r2;
	if (!(r1 == -1 || r2 == -1)) {
		if (r1 > r2) cout << "Alice" << endl;
		else if (r1 < r2) cout << "Bob" << endl;
		else cout << "Draw" << endl;
	} else {
		if (t1 < t2) cout << "Alice" << endl;
		else if (t1 > t2) cout << "Bob" << endl;
		else cout << "Draw" << endl;
	}

	return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int N,K;
P sushi[100010];//first:味　second:ネタ
bool sushiPicked[100010]={};
map<int,int> mp;//ネタをkeyにして、そのネタを何個取ってるかをvalueに保存

set<P> st;//１つしかとってないネタの集合
int main(){
    cin>>N>>K;
    for(int i=0;i<N;i++){
        cin>>sushi[i].second>>sushi[i].first;
    }
    sort(sushi,sushi+N);
    LL ans=0;
    int sushiNum=0;
    //おいしい方から種類が被らないように選ぶ
    for(int i=N-1;i>=0 && sushiNum<K;i--){
        if(mp.count(sushi[i].second)==0){
            mp[sushi[i].second]=1;
            ans+=sushi[i].first;
            sushiNum++;
            sushiPicked[i]=true;
            st.insert(sushi[i]);
        }
    }
    ans+=mp.size()*mp.size();//種類ボーナス

    ///Ｋ種類選べなかった場合おいしい方からネタの重複を許して選ぶ
    for(int i=N-1;i>=0 && sushiNum<K;i--){
        if(!sushiPicked[i]){
            mp[sushi[i].second]++;
            ans+=sushi[i].first;
            sushiNum++;
            sushiPicked[i]=true;
            st.erase(sushi[i]);
        }
    }
    
    for(int i=N-1;i>=0;i--){
        if(!sushiPicked[i]){
            int dif=sushi[i].first - (mp.size()*2-1) - (st.begin())->first;
            //cout<<dif<<endl;
            if( dif > 0){//１種類減らして最もおいしいものを選ぶのが得になるか
                mp.erase(st.begin()->second);
                st.erase(st.begin());
                ans+=dif;
            }else{
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

int main(){
	int N,M;
	cin >> N >> M;
	vector<P> A(N);
	rep(i,N){ int a,b; cin >> a >> b; A[i]=P(b,a); }
	sort(A.begin(),A.end());
	reverse(A.begin(),A.end());

	vector<int> sl;
	rep(i,M){ sl.push_back(i+1); }
	ll ans = 0;
	for(P p : A){
		int day = p.second;
		auto itr = lower_bound(sl.begin(),sl.end(),day);
		if(itr==sl.end())continue;
		ans += p.first;
		sl.erase(itr);
	}
	cout << ans << endl;
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
typedef pair <int, int> pii;

void solve() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = max(max(a * c, a * d), max(b * c, b * d));
  if ((a <= 0 && 0 <= b) || (c <= 0 && 0 <= d)) chkmax(ans, 0ll);
  cout << ans << endl;
}

signed main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>

using namespace std;

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

	if (N[0] == N[1] && N[1] == N[2]) {
		cout << "Yes" << endl;
	}
	else if (N[1] == N[2] && N[2] == N[3]) {
		cout << "Yes" << endl;
	}
	else if (N[0] == N[1] && N[1] == N[2] && N[2] == N[3]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;


	bool ok = true;
	for(int i = 0; i < s.size(); i++){
		if(i == a){
			if(s[i] != '-') ok = false;
		}
		else{
			if(!isdigit(s[i])) ok = false;
		}
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i,j,H,W;

	H = 1;
	W = 1;

	while(H != 0 || W != 0){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0){
			break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if((i+j)%2 == 0){
					printf("#");
				}
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 572
def main():
    H1,M1,H2,M2,K = [int(x) for x in input().split()]
    if M2 >= M1:
        diff = (H2-H1)*60 + M2-M1
    else:
        diff = (H2-H1)*60 + 60-M1+M2 -60
    if diff <= 0:
        print(0)
    else:
        print(diff - K)

if __name__ == '__main__':
    main()


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

int main() {
  int hoge[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;



  cout << hoge[K-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define pb push_back
#define prev prev_
#define stack stack_
#define inf 0x3f3f3f3f

typedef long long ll;

int n,m,q;
vector <int> vec[maxn];

int main(){
	scanf("%d %d %d",&n,&m,&q);
	rep(i,1,m){
		int l,r;
		scanf("%d %d",&l,&r);
		vec[l].pb(r);
	}
	rep(i,1,n) sort(vec[i].begin(),vec[i].end());
	rep(i,1,q){
		int l,r;
		scanf("%d %d",&l,&r);
		int ans = 0;
		rep(j,l,r){
			if ( vec[j].size() )
			ans += upper_bound(vec[j].begin(),vec[j].end(),r) - vec[j].begin();
		}
		printf("%d\n",ans);
	}
}



Measured memory_bytes: 4480
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

ll fact(ll n){
    if(n==0)return 1;
    else return n*fact(n-1)%MOD;
}
ll calc(ll n,ll k){
    if(k==0)return 1;
    ll m=n*n%MOD;
    if(k%2)return n*calc(m,k/2)%MOD;
    else return calc(m,k/2)%MOD;
}
ll comb(ll n,ll k){
    ll ret=fact(n);
    ret=ret*calc(fact(k),MOD-2)%MOD;
    ret=ret*calc(fact(n-k),MOD-2)%MOD;
    return ret;
}


int main() {
    ll n,k;
    cin>>n>>k;
    ll r = n-k;
    ll b =  k;


    for(ll i = 1;i<=k;i++){
        if(i-1>r){
            cout<<0<<endl;
        }else{
            ll b1 = comb(b-1,i-1);


            ll red = comb(r+1,i);
            cout<<(b1*red)%MOD<<endl;


           }

        }







    return 0;
}


Measured memory_bytes: 256
/*
	Name: None
	Copyright: zhangjingcanËùÓÐ£¬Î´¾­ÔÊÐí²»µÃ×ªÔØ
	Author: zhangjingcan
	Date:
	Description: C++ÎÄ¼þ
*/
#include <bits/stdc++.h>
using namespace std;
string s;
int a,b;
int main(int argc, char** argv) {
	ios::sync_with_stdio(false);
	cin>>a>>b;
	cin>>s;
	if(s[a]!='-'){
		cout<<"No\n";
	}else{
		s.erase(a,1);
		for(int i=0;i<s.size();i++){
			if(!(s[i]>='0'&&s[i]<='9')){
				cout<<"No\n";
				return 0;
			}
		}
		cout<<"Yes\n";
	}
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    const ll mod = 1000000007;
    ll N;
    cin >> N;
    vl A(N), sum(N+1);
    rep(i, N){
        cin >> A[i];
    }
    sum[0] = 0;
    rep(i, N){
        sum[i+1] = sum[i] + A[i];
    }

    ll ans = 0;
    rep(i, N-1){
       ans += A[i] * ((sum[N]-sum[i+1])%mod) % mod;
        ans %= mod;
    }
    cout << ans;
}


Measured memory_bytes: 6428
import math
N, M = list(map(int, input().split()))

# 2以上差があるときは、猿同士、犬同士が必ず隣り合うので0
if abs(N - M) > 1:
    re = 0
elif abs(N - M) == 1:
    re = (math.factorial(N) * math.factorial(M)) % (10**9 + 7)
else:
    re = (2 * math.factorial(N) * math.factorial(M)) % (10**9 + 7)

print(re)

Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
struct point {
    int    a, b;
    point *l, *r, *pa;
    point() { l = r = pa = NULL; }
    point(int aa, int bb) : a(aa), b(bb) { l = r = pa = NULL; };
};
point *root;
point *rightRotate(point *t) {
    point *s = t->l;
    t->l     = s->r;
    s->r     = t;
    return s;
}
point *leftRotate(point *t) {
    point *s = t->r;
    t->r     = s->l;
    s->l     = t;
    return s;
}
point *insert(point *p, int a, int b) {
    if (p == NULL) return new point(a, b);
    if (a == p->a) return p;
    if (a < p->a) {
        p->l = insert(p->l, a, b);
        if (p->b < p->l->b) p = rightRotate(p);
    } else {
        p->r = insert(p->r, a, b);
        if (p->b < p->r->b) p = leftRotate(p);
    }
    return p;
}
point *_del(point *p, int a);
point *del(point *p, int a) {
    if (p == NULL) return NULL;
    if (a < p->a)
        p->l = del(p->l, a);
    else if (a > p->a)
        p->r = del(p->r, a);
    else
        return _del(p, a);
    return p;
}
point *_del(point *p, int a) {
    if (p->l == NULL && p->r == NULL)
        return NULL;
    else if (p->l == NULL)
        p = leftRotate(p);
    else if (p->r == NULL)
        p = rightRotate(p);
    else {
        if (p->l->b > p->r->b)
            p = rightRotate(p);
        else
            p = leftRotate(p);
    }
    return del(p, a);
}
bool find(int a) {
    point *p = root;
    while (p) {
        if (a == p->a) return 1;
        if (a > p->a)
            p = p->r;
        else
            p = p->l;
    }
    return 0;
}
void dfs1(point *p) {
    if (!p) return;
    dfs1(p->l);
    printf(" %d", p->a);
    dfs1(p->r);
}
void dfs2(point *p) {
    if (!p) return;
    printf(" %d", p->a);
    dfs2(p->l);
    dfs2(p->r);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    int    ta, tb;
    string s;
    while (cin >> s) {
        if (s == "insert") {
            cin >> ta >> tb;
            //      if(!root)root=new point(ta,tb);
            //      else
            root = insert(root, ta, tb);
        } else if (s == "find") {
            cin >> ta;
            if (find(ta))
                printf("yes\n");
            else
                printf("no\n");
        } else if (s == "print") {
            dfs1(root);
            printf("\n");
            dfs2(root);
            printf("\n");
        } else if (s == "delete") {
            cin >> ta;
            root = del(root, ta);
        }
    }
    return 0;
}



Measured memory_bytes: 12732
<?php
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%s", $T);
$bool = true;
$SS = str_split($S);
$TT = str_split($T);
$dict = [];
$cnt = 0;
foreach ($SS as $k => $v) {
    if (!isset($dict[$v])) {
        $dict[$v] = $TT[$k];
    }
    if ($dict[$v] !== $TT[$k]) {
        $bool = false;
    }
}
$mmax = max(array_count_values($dict));
if ($mmax > 1) {
    $bool = false;
}
echo $bool ? "Yes" : "No";


Measured memory_bytes: 33272
#include <stdio.h>

int gcd(int a,int b);
void swap(int* a,int* b);

int main(void)
{
    int k=0,gcdAB=0;
    int sum=0;
    scanf("%d",&k);


    for(int h=1;h<=k;h++){
        for(int i=1;i<=k;i++){
            gcdAB=gcd(h,i);
            for(int j=1;j<=k;j++){
                sum+=gcd(gcdAB,j);
            }
        }
    }

    printf("%d",sum);
    return 0;
}

int gcd(int a,int b){
    int temp=0;
    if(a<b) swap(&a,&b);
    do{
        temp=b;
        b=a%b;
        a=temp;
    } while (b!=0);
    return a;
}

void swap(int* a,int* b){
    int temp=0;
    temp=*a;
    *a=*b;
    *b=temp;
}


Measured memory_bytes: 1704
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a>b)
		cout<<"a > b"<<endl;
	if(a<b)
		cout<<"a < b"<<endl;
	if(a==b)
		cout<<"a == b"<<endl;
	return 0;
}




Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    char x;
    cin >> a >> x >> b;
    if (x=='+')
    {
        cout << a+b << endl;
    }
    else
    {
        cout << a-b << endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define li(x) x.size()-1
#define oo 2000000000
#define inf 1000000000000000000
#define M 1000000007
typedef unsigned long long ll;
using namespace std;
const int N =3e5+10;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double Tau = 2*acos(-1);

int n , m;
char g[111][111];
char p[111][111];

int main() {
	cin >> n >> m ;
	for(int i = 0 ; i < n ; i++){
		scanf(" %s",g[i]);
		int ctr = 0;
		for(int j = 0; j < m ; j++){
			ctr+=(g[i][j]=='#');
		}
		if(ctr==0){
			for(int j = 0; j < m ; j++)p[i][j]=1;
		}
	}
	
	for(int i = 0 ; i < m ; i++){
		int ctr = 0;
		for(int j = 0; j < n ; j++){
			ctr+=(g[j][i]=='#');
		}
		if(ctr==0){
			for(int j = 0; j < n ; j++)p[j][i]=1;
		}
	}
	vector<vector<char> > v;
	vector<char> v2;
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){
			if(!p[i][j])v2.push_back(g[i][j]);
		}
		if(v2.size()){
			v.push_back(v2);
			v2.clear();
		}
	}
	for(int i = 0 ; i < v.size() ; i++){
		for(int j = 0 ; j < v[i].size() ; j++){
			cout << v[i][j];
		}
		cout << endl;
	}
    return 0;
}


Measured memory_bytes: 256