akhauriyash/Code-Regression huggingface dataset:
n = gets.chomp.to_i
ary = []
n.times do
    ary << gets.chomp.split.map(&:to_i)
end
ary.sort! { |a,b| b[1] <=> a[1]}
flag = false
now_at = ary[0][1]
n.times do |i|
    now_at = [now_at, ary[i][1]].min
    # p now_at
    now_at -= ary[i][0]
    if now_at < 0
        flag = true
        break
    end
end

if flag
    puts "No"
else
    puts "Yes"
end

Measured memory_bytes: 18552
#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
//#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-8
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define N 500005
//#define M 1000005
#define pi 3.14159265359
#define cpdd const pdd
#define hash Hash
#define list List
using namespace std;
typedef long long LL;
using namespace std;
int dp[2005][2005][2];
char c[2005][2005];
struct list{
	list* next,*before;
	int i;
	list(int _i):next(NULL),before(NULL){
		i=_i;
	}
};
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%s",c[i]+1);
	int a[2005];
	int ans=0;
	for(int i=1;i<=n;i++){ 
		for(int j=1;j<=m;j++){
			if(c[i][j]!=c[i][j-1]){
				dp[i][j][1]=dp[i-1][j][1]+1;
				dp[i][j][0]=0;
				a[j]=dp[i][j][1];
			}
			else{
				dp[i][j][1]=0;
				dp[i][j][0]=dp[i-1][j][0]+1;
				a[j]=dp[i][j][0];
			}
		}
		vector<list*> v[3005];
		for(int j=0;j<3005;j++)
		v[j].clear();
		list *head=new list(1);
		list *now=head;
		for(int j=2;j<=m;j++){
			list *l=new list(j);
			v[a[j]].pb(l);
		//	printf("%d ",a[j]);
			now->next=l;
			l->before=now;
			now=l; 
		}
		//printf("%d \n",now->i);
		now->next=new list(m+1);
		now->next->before=now;
		now=now->next;
		int Max=1;
		for(int j=i;j>=1;j--){
			for(int k=0;k<v[j].size();k++){
				Max=max(Max,v[j][k]->next->i-v[j][k]->before->i);
				v[j][k]->next->before=v[j][k]->before;
				v[j][k]->before->next=v[j][k]->next;
		//		printf("%d\n",v[j][k]->i);
				delete v[j][k];
			}
			//printf("Max:%d\n",Max);
			ans=max(ans,Max*j);
		}
		delete head;
		delete now;
		//printf("%d\n",ans); 
	}
	printf("%d\n",ans); 
}
/*
14%20,15#17
20,14-18
1#5,11,4%10,14-18,20,21
11,21,20,14-18,4%10,1#5

*/


Measured memory_bytes: 35712
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
A=get_i
puts A.inject{|res,x| res.gcd(x)}

Measured memory_bytes: 9476
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int calc(int n,I vec){
    int ins = 0;
    REP(a,vec.size()){
        ins += abs(vec.at(a)-n);
    }
    return ins;
}
int main(){
    CIN(N);CIN(T);
    I vec;
    pair<I,I> pa;
    int ins = 0;
    REP(a,N){
        CIN(b);
        vec.pb(b);
    }
    int mi = INF;
    int count1 = 0;
    int count2 = 0;
    REP(a,N){
        mi = min(mi,vec.at(a));
        if(vec.at(a) - mi > ins){
            ins =vec.at(a) - mi;
            count1 = 1;
            count2 = 1;
        }else if(vec.at(a) - mi == ins){
            count1++;
            count2++;
        }
    }
    COUT(min(count1,count2));
    return 0;
}


Measured memory_bytes: 892
X,Y,A,B,C=map(int,input().split())
P=sorted(map(int,input().split()), reverse=True)[:X]
Q=sorted(map(int,input().split()), reverse=True)[:Y]
R=sorted(map(int,input().split()), reverse=True)[:X+Y]
i,j=X-1,Y-1
for r in R:
    if i==-1 and j==-1:
        break
    elif j==-1:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
    elif i==-1:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    elif P[i]>Q[j]:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    else:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
print(sum(P)+sum(Q))

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  if(a + b == c || a + c == b || a == b + c)
    cout << "Yes" << endl;
  
  else
    cout << "No" << endl;
}

  
  



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleTest
{
    static partial class Program
    {

        static void Main(string[] args)
        {
            var n = Int();
            long sum=0;
            for(int i = 1; i <= n; ++i)
            {
                if (i % 3 == 0) continue;
                if (i % 5 == 0) continue;
                sum += i;
            }
            Console.WriteLine(sum);

        }

    }
    static partial class Program
    {
        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }
        public static int[] Ints()
        {
            return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        }
        public static long[] Longs()
        {
            return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        }
        public static int[][] MultiInts(int num)
        {
            var result = new int[num][];
            for(int i = 0; i < num; ++i)
            {
                result[i] = Ints();
            }
            return result;
        }
        public static T[] MultiItems<T>(int num, Func<string,T> parser)
        {
            var result = new T[num];
            for(int i =0; i < num; ++i)
            {
                result[i] = parser(Console.ReadLine());
            }
            return result;
        }
    }
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N + 2);
    vector<ll> B(N + 2, 0);
    for (int i = 1; i <= N + 1; i++) {
        cin >> A[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> B[i];
    }

    ll ans = 0;
    for (int i = 1; i <= N + 1; i++) {
        ll damage1 = min(A[i], B[i - 1]);
        A[i] -= damage1;
        B[i - 1] -= damage1;
        ll damage2 = min(A[i], B[i]);
        A[i] -= damage2;
        B[i] -= damage2;
        ans += damage1 + damage2;
    }

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


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

int main(){
  char C;
  cin>>C;
  
  
  if(C=='a'){
    cout<<'b'<<endl;
  }
   else if(C=='b'){
    cout<<'c'<<endl;
  } else if(C=='c'){
    cout<<'d'<<endl;
  } else if(C=='d'){
    cout<<'e'<<endl;
  } else if(C=='e'){
    cout<<'f'<<endl;
  } else if(C=='f'){
    cout<<'g'<<endl;
  } else if(C=='g'){
    cout<<'h'<<endl;
  } else if(C=='h'){
    cout<<'i'<<endl;
  } else if(C=='i'){
    cout<<'j'<<endl;
  } else if(C=='j'){
    cout<<'k'<<endl;
  } else if(C=='k'){
    cout<<'l'<<endl;
  } else if(C=='l'){
    cout<<'m'<<endl;
  } else if(C=='m'){
    cout<<'n'<<endl;
  } else if(C=='n'){
    cout<<'o'<<endl;
  } else if(C=='o'){
    cout<<'p'<<endl;
  } else if(C=='p'){
    cout<<'q'<<endl;
  } else if(C=='q'){
    cout<<'r'<<endl;
  } else if(C=='r'){
    cout<<'s'<<endl;
  } else if(C=='s'){
    cout<<'t'<<endl;
  } else if(C=='t'){
    cout<<'u'<<endl;
  } else if(C=='u'){
    cout<<'v'<<endl;
  } else if(C=='v'){
    cout<<'w'<<endl;
  } else if(C=='w'){
    cout<<'x'<<endl;
  } else if(C=='x'){
    cout<<'y'<<endl;
  } else if(C=='y'){
    cout<<'z'<<endl;
  }
}

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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int x = 0;
    int MAX = 0;
    rep(i, N){
        if(S[i]=='I'){
            x++;
        }else{
            x--;
        }
        MAX = max(MAX, x);
    }
    printf("%d\n", MAX);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  mem(a,x) memset(a,x,sizeof(a));
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;
int main()
{
    ft
    int i,j,k,n,m,l=0,r;
    cin>>n;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=n-1;j>=i;j--)
        {
            m=INT_MAX;
            for(k=i;k<=j;k++)
            {
                m=min(m,a[k]);
            }
            l+=m;
            for(k=i;k<=j;k++)
            {
                a[k]-=m;
            }
        }
    }
    cout<<l<<"\n";
    return 0;
}

Measured memory_bytes: 3624
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define mod 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
    return (x&(-x));
}
void solve(){
    ll a,b,c,k; cin>>a>>b>>c>>k;
    ll ans = 0;
    ans+=min(k,a);
    k-=ans;
    ll cnt = min(k,b);
    k-=cnt;
    ans-=min(k,c);
    cout<<ans;
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
        solve();
    }
}

Measured memory_bytes: 3648
import sys

# sys.stdin = open('c1.in')

n, T = map(int, input().split())
t = list(map(int, input().split()))
res = 0
t.append(10 ** 20)
for i in range(n):
    dif = t[i + 1] - t[i]
    if dif > T:
        res += T
    else:
        res += dif
print(res)


Measured memory_bytes: 25200
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

long long powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

int main(void){
    lint N;
    cin >> N;
    lint pow2=powmod(2,N);
    lint ans=0;
    lint C[N];
    rep(i,N) cin >> C[i];
    sort(C,C+N);
    rep(i,N){
      lint keisu=powmod(2,i);
      lint r=N-i-1;
      lint add=(powmod(2,r)+r*powmod(2,r-1))%MOD;
      add=(add*keisu)%MOD;
      ans=(ans+add*C[i])%MOD;
    }
    cout << (ans*pow2)%MOD << endl;
}

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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

struct ufds {
  int n;
  vector<int> p, s;
  ufds(int n = 0) : n(n), p(n), s(n, 1) {
    for (int i = 0; i < n; i++)
      p[i] = i;
  }
  int findSet(int i) {
    return p[i] == i ? i : (p[i] = findSet(p[i]));
  }
  bool inSameSet(int i, int j) {
    return findSet(i) == findSet(j);
  }
  int getSizeOfSet(int i) {
    return s[findSet(i)];
  }
  void unionSet(int i, int j) {
    i = findSet(i); j = findSet(j);
    if (i != j) {
      if (s[i] < s[j])
        swap(i, j);
      s[i] += s[j]; p[j] = i;
    }
  }
};

ll n, m, q;
bool c1[200000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n >> m >> q;
  ufds u(n);
  vector<pair<int, int>> e;
  int a, b, c;
  for (int i = 0; i < q; i++) {
    cin >> a >> b >> c;
    if (c == 0) {
      if (!u.inSameSet(a, b))
        u.unionSet(a, b), n--, m--;
    } else
      e.push_back({a, b});
  }
  ll cc = 0;
  for (pair<int, int> ed : e) {
    a = ed.first, b = ed.second;
    if (u.inSameSet(a, b)) {
      cout << "No\n";
      return 0;
    }
    if (!c1[u.findSet(a)])
      c1[u.findSet(a)] = true, cc++;
    if (!c1[u.findSet(b)])
      c1[u.findSet(b)] = true, cc++;
  }
  if (cc > 0 && n < 3) {
    cout << "No\n";
    return 0;
  }
  ll me = cc == 0 ? 0 : max(3LL, cc);
  ll ma = n * (n - 1) / 2;
  if (m < me || m > ma) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
}


Measured memory_bytes: 2168
import scala.io.StdIn.{readInt, readLine};
import scala.collection.immutable.Queue;

object Main {
    def main(args: Array[String]): Unit = {
        val info = readLine.split(" ").map(_.toInt);
        val graph: Array[List[Int]] = new Array[List[Int]](info(0)).map(a => Nil);
        for (i <- (0 until info(1))) {
            val c = readLine.split(" ").map(_.toInt);
            graph(c(0)) = c(1) :: graph(c(0));
            graph(c(1)) = c(0) :: graph(c(1));
        }
        val connList: Array[Int] = buildConnectionList(graph);
        for (i <- (0 until readInt)) {
            val q = readLine.split(" ").map(_.toInt);
            if (connList(q(0)) == connList(q(1))) println("yes") else println("no");
        }
    }
    
    def buildConnectionList(graph: Array[List[Int]]): Array[Int] = {
        val size = graph.length;
        val connList = new Array[Int](size);
        def go(que: Queue[Int], group: Int): Int = {
            que.dequeueOption match {
                case None => group + 1;
                case Some((src, restQue)) => {
                    val newQue = graph(src).filter(dst => connList(dst) == 0).foldLeft(restQue) { (q, dst) => 
                        connList(dst) = group; 
                        q.enqueue(dst);
                    }
                    go(newQue, group);
                }
            }
        }
        (0 until size).foldLeft(1) { (group, i) => 
            if (connList(i) == 0) {connList(i) = group;go(Queue(i), group);} else {group}
        }
        connList;
    }
}


Measured memory_bytes: 152412
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    vector<string> pic(2*h);
    for(int i = 0;i < h;i++){
      cin >> pic[2*i];
      pic[2*i+1] = pic[2*i];
    cout << pic[2*i] << endl << pic[2*i+1] << endl;      
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,h;cin>>a>>b>>h;
  cout<<(a+b)*h/2<<endl;

  return 0;

}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        int ans = 0;
        for (long current = inpt[0]; current <= inpt[1]; current*=2) {
            ans++;
        }
        Console.WriteLine(ans);
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



314159265 358979323846264338



";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


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

//===
// nCr mod p
// p is prime
// 1 <= k <= n <= 1e7

void init_comb(long long modulus);
void init_comb(void);
long long combination(long long n, long long k);
long long pow_mod(long long n, long long m);

long long _modulus = (long long)1e9 + 7;
long long fact[10000007];
long long fact_inv[10000007];

void init_comb(long long modulus) {_modulus = modulus; }
void init_comb(void)
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    for (int i = 2; i <= 1000000; i++) {
        fact[i] = fact[i - 1] * i % _modulus;
        fact_inv[i] = pow_mod(fact[i], _modulus - 2);
    }
}

long long combination(long long n, long long k)
{
    static long long f;

    if (f != _modulus) f = _modulus, init_comb();

    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;

    return fact[n] * (fact_inv[k] * fact_inv[n - k] % _modulus) % _modulus;
}

long long pow_mod(long long n, long long m)
{
    //n ** m;
    long long ret = 1;

    while (m) {
        if (m & 1) {
            ret = ret * n % _modulus;
        }

        n = n * n % _modulus;
        m = m >> 1;
    }

    return ret;
}
//===

#define sum(X) ((X) * ((X) + 1) / 2 % mod)

typedef long long ll;

const ll mod = (ll)(1e9) + 7;

ll n, m;
ll k;
ll ans;

int main()
{
    cin >> n >> m >> k;

    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            ll d = sum(i - 1) * m % mod + sum(n - i) * m % mod +
                sum(j - 1) * n % mod + sum(m - j) * n % mod;
            d %= mod;

            ans += d * combination(n * m - 2, k - 2) % mod;
            ans %= mod;
        }
    }

    ans = ans * pow_mod(2, mod - 2) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16888
#include<stdio.h>
#define N 100

int n,A[N][N],b[N];

void Breadth(int num, int res);

int main()
{
  int i,j,k,p,q;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      A[i][j]=0;
    }
  }
  for(i=0; i<n; i++){
    scanf("%d%d",&p,&k);
    p--;

    for(j=0; j<k; j++){
      scanf("%d",&q);
      q--;
      A[p][q]=1;
    }
  }
  for(i=0; i<n; i++){
    b[i]=-1;
  }
  Breadth(0,-1);
  for(i=0; i<n; i++){
    printf("%d %d\n",i+1,b[i]);
  }
  return 0;
}

void Breadth(int num,int res)
{
  int i;
  
  res++;
  b[num]=res;

  for(i=0; i<n; i++){
    if(A[num][i]==1){
      if(b[i]<=res && b[i]>=0)continue;
      Breadth(i,res);
    }
  }
}



Measured memory_bytes: 2092
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int p[100000];
int y[100000];
int z[100000];
int ans[100000];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int  Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

int gcd(int a, int b) {
	if (b == 0)return a;
	int tmp = a%b;
	a = b;
	b = tmp;
	return gcd(a, b);
}


int main() {
	int n, k;
	scanf("%d%d", &n, &k);

	int h[100000];
	REP(i, n) {
		scanf("%d", &h[i]);
	}
	QSort(h, 0, n - 1, 1);
	int min = INF;
	REP(i, n - k + 1) {
		min = Min(min, h[i + k - 1] - h[i]);
	}

	PRINTD(min);
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int x,y,i,j,count;
    count = 0;
    char S[256];
    scanf("%d %d",&x,&y);
  	if (x >= y){
      x = 10;
    }else{
      x = 0;
    }
    //scanf("%s",S);
    printf("%d",x);
    //printf("%s",S);
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <climits>
#define int long long
using namespace std;
typedef pair <int,int> P;
#define to first
#define co second
#define fi first
#define se second
const int INF=INT_MAX;
const int MAX_V=100000;
vector <P> G[MAX_V];
int v,d[MAX_V];
void dijk(int s){
  priority_queue <P,vector<P>,greater<P> > que;
  fill(d,d+v,INF);
  d[s]=0;
  que.push(P(0,s));
  for(;!que.empty();){
    P p=que.top(); que.pop();
    int v=p.se;
    if (d[v]<p.fi) continue;
    for(int i=0;i<(int)G[v].size();i++){
      P e=G[v][i];
      if(d[e.to]>d[v]+e.co){
	d[e.to]=d[v]+e.co;
	que.push(P(d[e.to],e.to));
      }
    }
  }
}
signed main(){

  cin>>v;
  for(int i=0,u,k;i<v&&cin>>u>>k;i++) for(int j=0,a,b;j<k&&cin>>a>>b;j++) G[u].push_back(P(a,b));
  dijk(0);
  for(int i=0;i<v;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;

}

Measured memory_bytes: 5572
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    ll n;
    cin>>n;
    string ans = "";
    while(n ){
        if(n%26 == 0){
            ans += 'z';
            n /= 26;
            --n;
        }
        else{
            ans += (char)('a'+n%26-1);
            n /= 26;
        }
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 3636
#include<stdio.h>

// 線形探索
int search(int A[],int n, int key){
    int i = 0;
    A[n] = key;
    while( A[i] != key) i++;
    return i != n;
}

int main(){
    int i, n, A[10000+1], q, key, sum=0;

    scanf("%d",&n);
    for(i=0; i<n; i++) scanf("%d" , &A[i]);

    scanf("%d", &q);
    for(i=0; i<q; i++){
        scanf("%d", &key);
        if(search(A,n,key)) sum++;
    }
    printf("%d\n",sum);

    return 0;
}



Measured memory_bytes: 2764
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        _n: usize,
        s: Chars,
        k: Usize1,
    }
    let k = s[k];
    for c in s {
        print!("{}", if c == k { c } else { '*' });
    }
}


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

#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
#define mp            make_pair
typedef long long     ll;

int a,b,c;
int arr[101][101][101];
int main()
{
 /*cin>>a>>b>c;
for(int i=0;i<a;i++){
    int x,y,z;cin>>x>>y>>z;
    arr[x][y][z]++;
}
  for(int i = 1 ; i<=100 ; ++i)
        for(int j = 1 ; j<=100 ; ++j)
            for(int a = 0 ; a<=m ; ++a)
            {
               arr[i][j][a] += arr[i-1][j][a] + arr[i][j-1][a];
                arr[i][j][a] -= arr[i-1][j-1][a];
            }*/
int s;cin>>s;
for(int i=s;i<=999999;i++){
    int a,b,c;int l=i;
    a=l%10;l/=10;
    b=l%10;l/=10;
    c=l;
    if(a==b&&b==c){
        cout<<i;return 0;
    }
}

}
/*
2
2
2 3
2
2 4
*/


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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> hs(N);
	rep(i, N)cin >> hs[i];

	int res = 0;
	for (int h : hs)if (h >= K)res++;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef long long int int64;
typedef unsigned long long int uint64;
typedef float float32;
typedef double float64;
typedef long double float128;


int main(){
    int N;
    cin >> N;
    int A[N+2];
    A[0] = 0;
    A[N+1] = 0;
    REP(i,N){
        cin >> A[i+1];
    }
    int sum=0;
    int ans;
    REP(i,N+1){
        sum += abs(A[i+1]-A[i]);
    }
    REP(i,N){
        ans = sum-abs(A[i+2]-A[i+1])-abs(A[i+1]-A[i])+abs(A[i+2]-A[i]);
        cout << ans;
        if(i!=N-1){
            cout << "\n";
        }
    }
}

Measured memory_bytes: 1664
import heapq
n = int(input())
a = list(map(int, input().split()))
fh_sum = [0]*(n+1) 
sh_sum = [0]*(n+1) 
fh_sum[0] = sum(a[:n])
sh_sum[-1] = sum(a[2*n:])

fh = a[:n]
heapq.heapify(fh)
for i in range(n):
  ai = a[n+i]
  heapq.heappush(fh, ai)
  small = heapq.heappop(fh)
  fh_sum[i+1] = fh_sum[i] + ai - small

sh = list(map(lambda x:-x, a[2*n:]))
heapq.heapify(sh)

for i in range(n):
  bi = a[2*n-i-1]
  heapq.heappush(sh, -1*bi)
  large = -1 * heapq.heappop(sh)
  sh_sum[n-i-1] = sh_sum[n-i] + bi - large 

ans = -float('inf')
for f, s in zip(fh_sum, sh_sum):
  ans = max(ans, f-s)

print(ans)

Measured memory_bytes: 37212
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.sort()
y.sort()
for i in range(-100,101):
    if x[N-1] < i <= y[0] and X < i <= Y:
        print("No War")
        break
    if i == 100:
        print("War")

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll a, b, k;

int main(){
	cin >> a >> b >> k;
	
	for(ll i = min(a, b); i >= 0; i--){
		if(a%i == 0 && b%i == 0){
			k--;
		}
		if(k == 0){
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        BigDecimal sum = new BigDecimal("0");

        for(int i=0; i<n; i++) {
            String a = sc.next();
            String b = sc.next();
            if(b.equals("JPY")) {
                sum = sum.add(new BigDecimal(a));
            } else {
                sum = sum.add(new BigDecimal(a).multiply(new BigDecimal("380000")));
            }
        }

        System.out.println(sum.toPlainString());

    }

}


Measured memory_bytes: 22228
#include<stdio.h>
int main(){
int a,b,c,x=0;
scanf("%d %d %d",&a,&b,&c);



while(a!=b){
if(c%a==0){
x++;
}
a++;
}
if(a==b) if(c%a==0) x++;
printf("%d\n",x);
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
char solve(char c)
{
  		if(c=='r')return 'p';
        if(c=='s')return 'r';
        if(c=='p')return 's';
}
int main()
{
  int n,k;
  cin>>n>>k;
  int r,s,p;
  cin>>r>>s>>p;
  map<char,int>a;
  a.insert(pair<char,int>('r',r));
  a.insert(pair<char,int>('s',s));
  a.insert(pair<char,int>('p',p));
  string st,ans;
  cin>>st;
  long long sum=0;
  for(int i=0;i<n;i++)
  {
    if(i<k)
    {
        ans.push_back(solve(st[i]));
        sum+=a[ans[i]];
    }
    else
    {
      //cout<<1<<endl;
      if(st[i]==st[i-k] && solve(st[i])==ans[i-k])
      {
        ans.push_back(st[i]);     
      }
      else 
      {
        ans.push_back(solve(st[i]));
        sum+=a[ans[i]];
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 640
ring = gets.chomp.split(//)
ring = ring * 2
str = gets.chomp
i = 0
bool = false
while i < ring.length / 2 and !bool
  bool = (ring[i, str.length].join == str)
  i += 1
end
if bool
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 6120
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

  static int n;
  static long ans;
  static List<Integer> a;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);

    in = br.readLine().split(" ");
    List<Integer> a = Arrays.stream(in).map(Integer::parseInt).collect(Collectors.toList());

    br.close();

    for (int i = 0; i < n; i+=2) {
      if(a.get(i) % 2 == 1) ans++;
    }

    out.println(ans);

    out.flush();
  }
}


Measured memory_bytes: 34340
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#define int long long 
#define pb push_back
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define bst ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

using namespace std;

const int N = 5e5 + 10, mod = 1e9 + 7, inf = 1e18 + 7;
const double pi = acos(-1);

int vis[N];

void solve() {
	//soln
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	int ans = 0;

	if(k <= n) {
		while(k--) {
			ans = a[ans];
		}
	} else {
		int st = 0;
		bool ok = 0;
		vector<int> bef, cyc;

		for(int i = 0; i < n + 2; i++) {
			if(vis[st])  {
				ok = 1;
				break;
			}
			vis[st] = 1;
			st = a[st];
		}
		memset(vis, 0, sizeof vis);
		if(ok) {
			while(!vis[st]) {
				vis[st] = 1;
				cyc.pb(st);
				st = a[st];
		 	}
		}
		int cur = 0;
		for(int i = 0; i < n + 2; i++) {
			if(vis[cur]) break;
			vis[cur] = 1;
			bef.pb(cur);
			cur = a[cur];
		}
		if(k < bef.size()) {
			ans = bef[k];
		} else {
			k -= bef.size();
			ans = cyc[k % cyc.size()];
		}
	}
	cout << ans + 1 << endl;
}
main() {
	bst;
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}


Measured memory_bytes: 10920
#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;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.size()-1] == b[0] and b[b.size()-1] == c[0])cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>

using namespace std;

int main() {

  int a;
  string s;
  cin >> a >> s;
  
  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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 n;
  cin >> n;
  vi a(n);
  REP(i, n) cin>>a[i];
  int all = 0;
  REP(i, n) all ^= a[i];
  REP(i, n) {
    int x = all ^ a[i];
    printf("%d%c",x,(i==n-1?'\n':' '));
  }

  return 0;
}

Measured memory_bytes: 4024
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

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

		System.out.println(X + Y / 2);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 22996
// 提出時に消す
// package app;

import java.util.Scanner;
import java.util.stream.LongStream;

// 提出時にMainに変更する
public class Main {
// public class ABC177C {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        final long MOD = 1000000007L;

        int n = sc.nextInt();

        long[] a = LongStream.range(0, n).map(e -> sc.nextLong()).filter(e -> e != 0).toArray();

        long ans = 0;

        long sum = 0;
        for (long item : a) {
            sum += item % MOD;
            sum = sum % MOD;
        }

        for (long i : a) {
            sum -= i % MOD;
            if (sum < 0) {
                sum += MOD;
            }
            ans += i * sum % MOD;
        }

        ans = ans % MOD;
        System.out.println(ans);

        sc.close();
    }
}

Measured memory_bytes: 62904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
ll arr[1000000];
ll mem[1000000]={0};
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	} 
	fill_n(mem,n,999999999);
	mem[0]=0; 
	for(int i=1;i<n;i++){
		for(int j=1;j<=min(i,k);j++){
			mem[i]=min(mem[i],mem[i-j]+abs(arr[i]-arr[i-j]));
		}
	}
	cout<<mem[n-1]<<endl;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 n, m, t, p;
  while(cin >> n >> m >> t >> p && n+m+t+p) {
  vector<vector<int64>> v(m, vector<int64>(n, 1));
  REP(i, t) {
    vector<vector<int64>> nv(m, vector<int64>(n, 0));
    int64 ty, c;
    cin >> ty >> c;
    if (ty == 1) {
      REP(y, m) {
        REP(x, n-c) {
          nv[y][x] += v[y][x+c];
        }
        REP(x, c) {
          nv[y][c-x-1] += v[y][x];
        }
      }
    } else {
      REP(x, n) {
        REP(y, m-c)
          nv[y][x] += v[y+c][x];
        REP(y, c)
          nv[c-y-1][x] += v[y][x];
      }
    }
    swap(nv, v);
  }
  int64 res = 0;
  REP(i, p) {
    int64 x, y;
    cin >> x >> y;
    cout << v[y][x] << endl;
  }
  }
}


Measured memory_bytes: 3172
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n = int(input())
    s = [input() for i in range(n)]
    r = {}
    for x in s:
        r[x] = r.get(x, 0) + 1

    for i in ['AC', 'WA', "TLE", "RE"]:
        print("{} x {}".format(i, r.get(i, 0)))

main()


Measured memory_bytes: 16492
#include <bits/stdc++.h>
	
using namespace std;
	
#define endl "\n"
#define ll long long
#define vi vector <int >
#define vii vectir < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define a first
#define b second


int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	int t;
	cin >> t;
	ll resp = 0;
	string arr[10000];
	int ari[10000];
	forn(i, t){
		cin >> arr[i] >> ari[i];
	}
	string aux;
	cin >> aux;
	bool g = true;
	forn(i, t){
		if(g){
			if(aux == arr[i]){
				g = false;
			}
		}else{
			resp += ari[i];
		}
	}
	cout << resp << endl;

	return 0;
}

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<pair<int, int>> idx;

    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            int t = i;
            int cnt = 0;
            while (s[i] == '0') {
                cnt++;
                i++;
            }

            idx.push_back(make_pair(t, cnt));
        }
    }
    idx.push_back(make_pair(n, 0));

    int ans = 0;
    if (idx.size() <= k + 1) {
        ans = n;
    } else {
        int p = 0;
        for (int i = 0; i < idx.size() - k; i++) {
            ans = max(ans, idx[i + k].first - p);

            p = idx[i].first + idx[i].second;
        }
    }

    cout << ans << endl;
}

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

bool judgePrimeNumber( int a )
{
    for( int i = 2; i <= sqrt(a); i++ )
        if( a % i == 0 )
            return false;
    return true;
}

int main()
{
    int n;
    bool a[1000000];
    
    a[0] = a[1] = false;
    for( int i = 2; i < 1000000; i++ )
        a[i] = judgePrimeNumber(i);

    while( cin >> n )
    {
        if( !n )
            break;

        int cnt = 0;
        for( int i = 2; i <= n / 2; i++ )
            if( a[i] && a[n-i] )
                cnt++;
            
        cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

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

    vector<long long> x(N), y(N), z(N);
    rep(i,N) cin >> x[i] >> y[i] >> z[i];

    long long ans = 0;

    rep(k,8) {
        long long sum = 0;
        vector<long long> a(N, 0);
        rep(i,N) {
            a[i] += (k & bit(2) ? x[i] : (-1) * x[i]);
            a[i] += (k & bit(1) ? y[i] : (-1) * y[i]);
            a[i] += (k & bit(0) ? z[i] : (-1) * z[i]);
        }
        sort(a.begin(), a.end(), greater<long long>());
        rep(i,M) sum += a[i];
        ans = max(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from copy import deepcopy

n, m, q = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]
pq = [list(map(int, input().split())) for _ in range(q)]

cnt = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in lr:
    cnt[l][r] += 1

acc = deepcopy(cnt)
for i in range(n):
    for j in range(n):
        tmp = acc[i][j + 1] + acc[i + 1][j] - acc[i][j]
        acc[i + 1][j + 1] += tmp

for p, q in pq:
    p -= 1
    ans = acc[q][q] - acc[p][q] - acc[q][p] + acc[p][p]
    print(ans)


Measured memory_bytes: 130244