akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll k, a, b;
    cin >> k >> a >> b;
    if (b - a <= 2) {
        cout << k + 1 << endl;
        return 0;
    }

    ll ans=1;
    for (ll i = 0; i < k; i++) {
        if (k - i >= 2 && ans >= a) {
            ans += b - a;
            i++; 
        }
        else {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main() {
    string S;
    cin >> S;
 
    int cnt = 0;
    int ans = 0;
 
    for (auto i : S) {
        if ( i != 'A' && i != 'C' && i != 'G' && i != 'T' ) cnt = 0;
        else if ( ++cnt > ans ) ans = cnt;
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x, a, b;
		x = sc.nextInt();
		a = sc.nextInt();
		b = sc.nextInt();
		
		sc.close();
		
		String ans[] = {"delicious", "safe", "dangerous"};
		
		int ansnum = 0, tmp = b - a;
		
		if(tmp > 0 && tmp <= x)ansnum = 1;
		else if(tmp > x)ansnum = 2;
		System.out.println(ans[ansnum]);
		
	}

}


Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int i = 1,r=a[0],ans=-1;
	while (i <= n&&ans==-1) {
		if (r == 2) {
			ans = i;
		}
		r = a[r - 1];
		i++;
	}
	cout << ans << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main(){
  int n,h,w;
  cin>>h>>w;
  cin>>n;
  int a[n+1];
  for(int i=1;i<=n;i++) cin>>a[i];
  int t=1;
  int c[h+1][w+1]={};
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(a[t]==0) t++;
      c[i][j]=t;
      a[t]--;
    }
    i++;
    if(i>h) break;
    for(int j=w;j>=1;j--){
      if(a[t]==0) t++;
      c[i][j]=t;
      a[t]--;
    }
  }

  for(int i=1;i<=h;i++){
    cout<<c[i][1];
    for(int j=2;j<=w;j++){
      cout<<" "<<c[i][j];
    }
    if(i==h) break;
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
    // Your code here!
    //値の取得と初期化
    int r,c;
    cin>>r>>c;
    int A[r+2][c+2];
    for(int i=0; i<r+2; i++){
        for(int j=0; j<c+2; j++){
            A[i][j]=0;
        }
    }
    for(int i=1; i<=r; i++){
        for(int j=1; j<=c; j++){
            cin>>A[i][j];
        }
    }
     
    
    //計算と代入
    //行方向
    for(int i=1; i<=r; i++){
        int sum=0;
        for(int j=1; j<=c; j++){
            sum += A[i][j];
        }
        A[i][c+1] = sum;
    }
    //列方向
    for(int j=1; j<=c; j++){
        int sum=0;
        for(int i=1; i<=r; i++){
            sum += A[i][j];
        }
        A[r+1][j] = sum;
    }
    
    //右端
    int sum=0;
    for(int j=1; j<=c; j++){
        sum+=A[r+1][j];
    }
    A[r+1][c+1]=sum;
    
    //出力
    for(int i=1; i<=r+1; i++){
        for(int j=1; j<=c+1; j++){
            if(j!=c+1){
                cout<<A[i][j]<<" ";
            }
            else{
                cout<<A[i][j]<<endl;
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    vector<long long> L(M),R(M);
    for(int i = 0; i < M; i++){
        cin >> L[i] >> R[i];
    }
    sort(L.begin(),L.end());
    sort(R.begin(),R.end());
    if(R[0] >= L[M-1]) cout << R[0] - L[M-1] + 1 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 1792
n=int(input())
t,a=map(int,input().split())
h=input().split()
h=list(map(int,h))
b=[]
for i in range(n):
    b.append(abs(a-(t-0.006*h[i])))   
min=b[0]
if n!=1:
    j=0
    for i in range(1,n):
        if b[i]<min:
            min=b[i]
            j=i  
    print(j+1)            
else:
    print(1)



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

int main() {
  int a,b;
  cin>>a>>b;
  vector<vector<string>> vec(a, vector<string>(b));
  string oomozi="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
 for (int i = 0; i <a; i++) {
    for (int j = 0; j <b; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  
 for (int i = 0; i <a; i++) {
    for (int j = 0; j <b; j++) {
    if(vec.at(i).at(j)=="snuke"){
      cout<<oomozi.at(j)<<i+1<<endl;
    }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <array>

using namespace std;

struct Process {
	string name;
	int time;
};

class ProcessQueue {
public:
  ProcessQueue() : head(), tail(), queue() {};
  virtual ~ProcessQueue() {};

  bool push(Process& process) {
    if (isFull()) {
      return false;
    }
    queue[head] = process;
    head++;
    if (head == MAX) {
      head = 0;
    }
    return true;
  }

  Process& pop() {
    if (isEmpty()) {
      // TODO: throw exception.
    }
    Process& value = queue[tail];
    tail++;
    if (tail == MAX) {
      tail = 0;
    }
    return value;
  }

  bool isEmpty() {
    return head == tail;
  }

  bool isFull() {
    return (head + tail) == MAX;
  }
private:
  static const int MAX = 100000;
  array<Process, MAX> queue;
  int head;
  int tail;
};

static void inputProcess(ProcessQueue& processQueue, int n) {
  Process in;
  for (int i = 0; i < n; i++) {
    cin >> in.name  >> in.time;
    processQueue.push(in);
   }
}

int main() {
  int n, q;
  cin >> n >> q;

  ProcessQueue processQueue;
  inputProcess(processQueue, n);

  int total = 0;
  while (!processQueue.isEmpty()) {
    Process now = processQueue.pop();
    if (now.time <= q) {
      total += now.time;
      cout << now.name << ' ' << total << endl;
    } else {
      now.time -= q;
      total += q;
      processQueue.push(now);
    }
  }
  
  return 0;
}



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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> b(m);
  rep(i, m) {
    int k; cin >> k;
    rep(j, k) {
      int s; cin >> s;
      --s;
      b[i].push_back(s);
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];

  int ans = 0;
  for(int bit = 0; bit < 1<<n; ++bit) {
    bool ok = true;
    rep(i, m) {
      int count = 0;
      for(auto s : b[i]) {
        if(bit & 1<<s) ++count;
      }
      if(count % 2 != p[i]) ok = false;
    }
    if(ok) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static Dictionary<int, long> dic = new Dictionary<int, long>();
    static void Main() {
        int N = cin.Int();
        for (int i = N; i >= 2; i--) {
            prime_factorization(i);
        }
        long ans = 1;
        foreach (var v in dic.Values) {
            ans = (ans % 1000000007 * (v + 1)) % 1000000007;
        }
        Console.WriteLine(ans);
        Console.ReadLine();
    }

    static void prime_factorization(int n) //Key:素数, Value:指数
{
        int i = 2, tmp = n;
        while (i * i <= n) {
            if (tmp % i == 0) {
                if (dic.ContainsKey(i)) dic[i]++;
                else dic[i] = 1;
                tmp /= i;
            }
            else i++;
        }
        if (tmp > 1) {
            if (dic.ContainsKey(tmp)) dic[tmp]++;
            else dic[tmp] = 1;
        }
    }

}

Measured memory_bytes: 13152
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;
ll num[ten52];
ll path[ten52];

int main(void)
{
    //double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=0,save;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    //char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n;
    cin>>s;
    if(n<s.size())
    {
        for(i=0;i<n;i++) cout<<s[i];
        cout<<"...";
    }
    else
        cout<<s;
    return 0;
}





Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;

int Digit(long long x) {
  int n = 0;
  for (long long i = x; i > 0; i /= 10)
    ++n;
  return n;
}

int F(long long a, long long b) {
  return max(Digit(a), Digit(b));
}

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

  long long N;
  cin >> N;
  const int bound = (int)sqrt(N);
  int ans = Digit(N);
  for (long long i = 2; i <= bound; ++i) {
    if (N % i != 0) continue;
    ans = min(ans, F(i, N / i));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

using Graph = vector<vector<ll>>;
Graph G;
vector<ll> d;

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	G.resize(N);
	d.assign(N, -1);
	for (ll i = 0; i < M; ++i)
	{
		ll a, b; cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	queue<ll> que;
	que.push(0);
	d[0] = 0;

	while (!que.empty())
	{
		ll now = que.front(); que.pop();

		for (auto &nv : G[now])
		{
			if (d[nv] != -1) continue;
			d[nv] = d[now] + 1;
			que.push(nv);
		}
	}

	std::cout << (d[N-1] == 2 ? "POSSIBLE" : "IMPOSSIBLE")<< std::endl;
}


Measured memory_bytes: 15208
class UnionFind():
    def __init__(self, n):
        self.r = [-1] * n
    
    def root(self, x):
        if self.r[x] < 0:
            return x
        
        self.r[x] = self.root(self.r[x])
        return self.r[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        
        if self.r[x] > self.r[y]:
            x, y = y, x
        
        self.r[x] += self.r[y]
        self.r[y] = x

        return True
    
    def size(self, x):
        return -self.r[self.root(x)]


N, M = map(int, input().split())

UF = UnionFind(N)
for i in range(M):
    A, B = map(int, input().split())
    A, B = A - 1, B - 1
    UF.unite(A, B)

ans = 0
for i in range(N):
    ans = max(ans, UF.size(i))

print(ans)

Measured memory_bytes: 14664
input = gets.chomp.split
a = input[0].to_i
b = input[1].to_i
c = input[2].to_i

left = (c - a - b) ** 2
right = 4 * a * b
c_a_b = c - a - b > 0 ? true : false

if c_a_b && left > right
    puts "Yes"
else
    puts "No"
end

# if c_a_b
#     if left > right
#         puts "Yes"
#     else
#         puts "No"
#     end
# else
#     if left < right
#         puts "Yes"
#     else
#         puts "No"
#     end
# end

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

int main() {

  while (1) {

    string in;
    cin >> in;
    if (in == "0") break;

    int num_a = 0, num_b = 0;
    for (int i = 1; i < in.size(); i++) {

      if (in[i] == 'A') num_a++;
      else if (in[i] == 'B') num_b++;

    }

    if (num_a > num_b) num_a++;
    else if (num_b > num_a) num_b++;

    cout << num_a << " " << num_b << endl;
  }

	return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;


int main() {
    int a,b,c;
    cin>>a>>b>>c;
    int cur=a;
    int ans=0;
    while(cur<=c){
        ans+=b;
        cur+=a;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a, b = map(int, input().split())
counts = [0] * 3
for q in map(int, input().split()):
  if q <= a:
    counts[0] += 1
  elif a + 1 <= q <= b:
    counts[1] += 1
  else:
    counts[2] += 1

print(min(counts))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>
#include <iomanip>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

typedef unsigned long long u64;
typedef long long i64;

int n, m;

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

        cin >> n >> m;

        int a,b;
        a = -1;
        b = 1000000;
        REP(i,m) {
                int p,q;
                cin >> p >> q;

                a = max(a,p);
                b = min(b,q);
        }

        if (a > b)
                cout << 0 << endl;
        else
                cout << b - a + 1 << endl;


        return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    int count = 0;

    if (s[0] == '1') count++;
    if (s[1] == '1') count++;
    if (s[2] == '1') count++;

    cout << count << endl;

    return 0;
}



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

long long int n;
long long int h[100005], dp[100005];

void init() {
	for (int i = 0; i < n + 3; i++) dp[i] = -1;
}


long long int tab() {
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);

	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
			    dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	return dp[n - 1];
}

int main() {
	cin >> n;
	init();
	for (int i = 0; i < n; i++) cin >> h[i];
	cout << tab() << endl;
	

	return 0;
}


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

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

  vector<int> a(N);
  rep(i, N) cin >> a[i];

  ll ans = 0;
  rep(i, N - 1) {
    int n = a[i] + a[i + 1];
    if (n > x) {
      if (a[i + 1] >= n - x)
        a[i + 1] -= n - x;
      else {
        a[i] -= n - x - a[i + 1];
        a[i + 1] = 0;
      }
      ans += n - x;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 768
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>
 
using namespace std;

int a[4][3][10] = {};

void Calculate()
{
   for(int i = 0; i < 4; i++)
   {
       for(int j = 0; j < 3; j++)
       {
           for(int m = 0; m < 10; m++)
           {
               cout<<" "<<a[i][j][m];
           }
           
           cout<<endl;
       }
       
       if(i < 3)
       {
        cout<<"####################"<<endl;
       }
   }
}
 
void Solution(int n)
{
   for(int i = 0; i < n; i++)
   {
       int d, f, r, v;
       
       cin>>d>>f>>r>>v;
       
       a[d - 1][f - 1][r - 1] += v;
       
   }
   
}
 
int main()
{
    int n ;
    cin>>n;
    Solution(n);
    Calculate();
    return 0;
}

Measured memory_bytes: 1160
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.math.BigInteger;
//2 out of 26 done
public class Main { //CHANGE TO MAIN WHEN SUBMITTING
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int[][] a = new int[n][3];
        for(int i = 0; i<n; i++){
            for(int j = 0; j<3; j++){
                a[i][j] = in.nextInt();
            }
        }
        int[][] dp = new int[n][3];
        dp[0][0] = a[0][0];
        dp[0][1] = a[0][1];
        dp[0][2] = a[0][2];
        for(int i = 1; i<n; i++){
            for(int j = 0; j<3; j++){
                dp[i][j] = -1;
                for(int k = 0; k<3; k++){
                    if(k==j){

                    }
                    else{
                        dp[i][j] = Math.max(dp[i][j],dp[i-1][k]+a[i][j]);
                    }
                }
            }
        }
        out.println(Math.max(dp[n-1][0],Math.max(dp[n-1][1],dp[n-1][2])));
        out.close();
    }

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

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

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

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

        public long nextLong() {
            return Long.parseLong(next());
        }

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

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



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

int main()
{
	int64_t n, a, b;
	cin >> n >> a >> b;

	auto pow_mod = [](int64_t a, int64_t n, int64_t mod) {
		int64_t r = 1;
		for (; n; n >>= 1)
		{
			if (n & 1)
			{
				(r *= a) %= mod;
			}
			(a *= a) %= mod;
		}
		return r;
	};

	int64_t mod = 1000000007;

	int64_t ans = (pow_mod(2, n, mod) + mod - 1) % mod;

	{
		int64_t tmp = 1;
		for (int64_t x = n; n - a < x; x--)
		{
			(tmp *= x % mod) %= mod;
		}
		for (int64_t x = a; 0 < x; x--)
		{
			(tmp *= pow_mod(x, mod - 2, mod)) %= mod;
		}

		(ans += mod - tmp) %= mod;
	}
	{
		int64_t tmp = 1;
		for (int64_t x = n; n - b < x; x--)
		{
			(tmp *= x % mod) %= mod;
		}
		for (int64_t x = b; 0 < x; x--)
		{
			(tmp *= pow_mod(x, mod - 2, mod)) %= mod;
		}

		(ans += mod - tmp) %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a, b;
        String op = "";

        while(!op.equals("?")){
            a = sc.nextInt();
            op = sc.next();
            b = sc.nextInt();

            //if(op == "?") break;;
            switch(op){
                case "+":
                System.out.println(a + b);
                break;
            case "-":
                System.out.println(a - b);
                break;
            case "*":
                System.out.println(a * b);
                break;
            case "/":
                System.out.println(a / b);
                break;
                default:
                break;
            }
        }
        
    
        sc.close();
    }
}


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

int main() {
    vector<vector<char>> field(3, vector<char>(3));
    rep(i, 3) rep(j, 3) cin >> field.at(i).at(j);
    string ans = "";
    rep(i, 3) ans += field.at(i).at(i);
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    cout << n/3 << endl;

    return 0;
}

Measured memory_bytes: 256
s = int(input())
a = [s]
ans = -1
for i in range(1000000):
    if ans == -1:
        if a[-1] % 2 == 0:
            a.append(a[-1]/2)
        else:
            a.append(3*a[-1]+1)    

        for j in range(len(a)-1):
            if a[-1] == a[j]:
                ans = len(a)
                break
    else:
        print(ans)
        break

Measured memory_bytes: 3060
use std::io::*;

struct Stdio {
    sin : Stdin,
    sout : Stdout,
    buf : Vec<String>,
    len : usize,
    cnt : usize,
}

impl Stdio {
    fn new() -> Stdio  {
        Stdio {
            len : 0,
            cnt : 0,
            sin : stdin(),
            sout : stdout(),
            buf : Vec::new(),
        }
    }
    
    fn read_line(&mut self) {
        let mut s = String::new();
        let mut loc = self.sin.lock();
        loc.read_line(&mut s).unwrap();
        self.buf = s.trim().split_whitespace().map(|s| s.to_string()).collect();
        self.len = self.buf.len();
        self.cnt = 0;
    }

    fn read_i32(&mut self) -> i32 {
        if self.len == self.cnt {
            self.read_line();
        }
        let ret = self.buf[self.cnt].parse::<i32>().ok().unwrap();
        self.cnt += 1;
        ret
    }

    fn read_string(&mut self) -> String {
        if self.len == self.cnt {
            self.read_line();
        }
        let ret = self.buf[self.cnt].clone();
        self.cnt += 1;
        ret
    }
    fn write(&mut self , s : &str) {
        write!(self.sout ,"{}" ,s).unwrap();
    }
}

fn main() {
    let mut stdio = Stdio::new();
    let r = stdio.read_string();
    let g = stdio.read_string();
    let b = stdio.read_string();
    let rgb = r + &g + &b;
    let rgb :i32 = rgb.parse().unwrap();
    if rgb % 4 == 0 {
        stdio.write("YES");
    } else {
        stdio.write("NO");
    }

}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <stack>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n, m; cin >> n >> m;

    cout << abs(n - 2) * abs(m - 2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;


int main(void) {
    int n, i, j;
    ll ans = 0;
    string s;
    vector<int> r, g, b, em;

    cin >> n >> s;

    for (i = 0; i < n; i++) {
        if (s[i] == 'R') r.push_back(i);
        if (s[i] == 'G') g.push_back(i);
        if (s[i] == 'B') b.push_back(i);
    }

    for (i = 0; i < n - 2; i++) for (j = i + 1; j < n - 1; j++) {
        if (s[i] != s[j]) {
            vector<int>& t = em;
            if (s[i] != 'B' && s[j] != 'B') t = b;
            else if (s[i] != 'R' && s[j] != 'R') t = r;
            else if (s[i] != 'G' && s[j] != 'G') t = g;
            ans += t.end() - lower_bound(t.begin(), t.end(), j + 1);
            if (j * 2 - i < n && s[i] != s[j * 2 - i] && s[j] != s[j * 2 - i]) {
                ans--;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

use std::mem;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let N: usize = sc.read();
    let S: String = sc.read();
    let T: String = sc.read();

    let mut ans: String = "".to_string();
    for i in 0..(N * 2) {
        if i % 2 == 0 {
            ans.push(S.chars().nth(i / 2).unwrap());
        } else {
            ans.push(T.chars().nth(i / 2).unwrap());
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV 998244353
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-10;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding space */
ll dp[301][100000] = {};
ll dp2[301][100000] = {};
int main(){
  int n; cin >> n;
  ll sum = 0;
  vt<ll> in(n); rep(i,n)  cin >> in[i], sum += in[i];
  ll ans = pow(3,n,DIV);
  dp[0][0] = dp2[0][0] = 1;
  rep(i,n){
    rep(j,100000){
      dp[i+1][j+in[i]] += dp[i][j];
      dp[i+1][j] += dp[i][j]*2;
      dp[i+1][j] %= DIV;
      dp[i+1][j+in[i]] %= DIV;
      
      dp2[i+1][j+in[i]] += dp2[i][j];
      dp2[i+1][j] += dp2[i][j];
      dp2[i+1][j] %= DIV;
      dp2[i+1][j+in[i]] %= DIV;
    }
  }
  //ans_d -= (cnt)*(cnt-1)/2;
  ll ans_d = 0;
  ll cnt = 0;
  rep(i,100000){
    if(i >= (sum+1)/2)ans_d += dp[n][i];
    ans_d %= DIV;
  }
  if(sum%2 == 0)cnt += dp2[n][sum/2], cnt %= DIV;
  cerr << ans << " " << ans_d << " " << cnt << endl;
  ans += 10LL * DIV - 3*ans_d;
  ans %= DIV;
  cout << (ans + 3*cnt)%DIV<< endl;
}

Measured memory_bytes: 469760
#include <stdio.h>
#include <iostream>
#include <list>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()
{
    list<int> lst;
    //list<int>::reverse_iterator ritr;
    list<int>::iterator itr;

    int loop, dis = 0;

    int queryNum, query;
    int num, dd;

    int d = 0;
    scanf("%d", &queryNum);
    itr = lst.begin();

    for (loop = 0; loop < queryNum; loop++)
    {
        scanf("%d", &query);
        switch (query)
        {
        case 0:
            scanf("%d", &num);
            itr = lst.insert(itr, num);
            break;
        case 1:
            scanf("%d", &d);
            if (d > 0)
            {
                while (d != 0)
                {
                    d--;
                    itr++;
                }
            }
            else
            {
                while (d != 0)
                {
                    d++;
                    itr--;
                }
            }
            break;
        case 2:
            itr = lst.erase(itr);
            break;
        default:
            break;
        }
    }


    for (itr = lst.begin(); itr != lst.end();itr++)
    {
        printf("%d\n", *itr);
    }


    return 0;
}


Measured memory_bytes: 18744
import java.util.Scanner;

public class Main {
    public static boolean isPalindrome(String s){
        for(int i=0;i<s.length()/2;i++){
            if(s.charAt(i)!=s.charAt(s.length()-1-i)){
               return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner scan= new Scanner(System.in);
        String s= scan.next();
        if(isPalindrome(s)){
            String s1,s2;
            s1=s.substring(0,(s.length()-1)/2);
            //System.err.println(s1);
            s2=s.substring((s.length()+3)/2-1,s.length());
            //System.err.println(s2);
            if(isPalindrome(s1)&&isPalindrome(s2)){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstdlib> 
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define ll long long int
#define ld long double
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define ForA(i,a,b) for(int i = a; i < b; i++)
#define ForA1(i,a,b) for(int i = b - 1; i >= a; i--)
#define ForB1(i,a,b) for(int i = b; i > a; i--)
#define ForB(i,a,b) for(int i = a; i <= b; i++)
#define INT_SIZE 18 
#define maxn 110
#define Maxn 100010

using namespace std;

const ll INF = (ll)(8e18);
const ll MOD = 1000000007;

ll w[maxn],v[maxn], dp[maxn][Maxn];

int main()
{
    IOS;
    ll n,W; cin >> n >> W;
    ForB(i,1,n) cin >> w[i] >> v[i];
    ForB(i,0,maxn - 1){
        ForB(j,0,Maxn - 1) dp[i][j] = INF;
    }
    ForB(i,1,n) dp[i][v[i]] = w[i];
    ForB(i,1,n){
        ForB(j,1,Maxn){
           if(j >= v[i])
             dp[i][j] = min(dp[i][j], min(dp[i - 1][j],
                             dp[i - 1][j - v[i]] + w[i])); 
           else dp[i][j] = dp[i - 1][j];                  
        }
    }
    ll ans = 0;
    for(ll i = Maxn - 1; i > 0; i--){
        if(dp[n][i] <= W && dp[n][i] > 0){
            ans = i;
            break;
        }
    }
    cout << ans << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0 ;
}


Measured memory_bytes: 86272
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,i,cnt,cnt1=0;
	string s;
	char ch;
	cin>>n>>s;
	if(n==1)
	cout<<"No"<<endl;
	else
	{
		for(ch='a';ch<='z';ch++)
	    {
		    cnt=0;
	    	for(i=0;s[i]!='\0';i++)
	    	{
    			if(s[i]==ch)
	    		cnt++;
    		}
	    	if(cnt%2!=0)
	    	{
		    	cnt1++;
		    	break;
		    }
    	}
    	if(cnt1==1)
    	cout<<"No"<<endl;
    	else
    	cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3628
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		int[] c = new int[n];
		int[] r = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = scanner.nextInt();
			r[i] = scanner.nextInt();
		}
		List<Integer>[] lists = new List[n];
		for (int i = 0; i < n; i++)
			lists[i] = new ArrayList<Integer>();
		for (int i = 0; i < k; i++) {
			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;
			lists[a].add(b);
			lists[b].add(a);
		}
		PriorityQueue<Point> pq = new PriorityQueue<Point>();
		pq.offer(new Point(0, 0, 0));
		boolean[][] v = new boolean[n][n];
		while (!pq.isEmpty()) {
			Point p = pq.poll();
			if (p.b == n - 1) {
				System.out.println(p.cost);
				return;
			}
			if (v[p.a][p.b])
				continue;
			v[p.a][p.b] = true;

			pq.offer(new Point(p.cost + c[p.b], r[p.b], p.b));
			if (p.a > 0)
				for (int x : lists[p.b]) {
					pq.offer(new Point(p.cost, p.a - 1, x));

				}

		}
	}

	class Point implements Comparable<Point> {
		int cost, a, b;

		@Override
		public String toString() {
			return "Point [cost=" + cost + ", a=" + a + ", b=" + b + "]";
		}

		public Point(int cost, int a, int b) {
			super();
			this.cost = cost;
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Point o) {
			return cost - o.cost;
		}

	}
}

Measured memory_bytes: 77420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.HCPC2019_GW_Div1
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            List<int> res = new List<int>();
            while (true)
            {
                int n = ReadInt();
                if (n == 0) break;

                int[] array= ReadInts();
                Array.Sort(array);
                int delta = int.MaxValue;
                for (int i = 0; i < n - 1; i++)
                {
                    delta = Min(delta, array[i + 1] - array[i]);
                }
                res.Add(delta);
            }

            for (int i = 0; i < res.Count; i++) WriteLine(res[i]);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 15968
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    int n = x * 3 + y;
    cout << n / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

class SCC:

    def __init__(self, n):
        self.n = n
        self.graph = [[] for i in range(n)]
        self.graph_rev = [[] for i in range(n)]
        self.used = [False]*n

    def add_edge(self, fr, to):
        if fr == to:
            return
        self.graph[fr].append(to)
        self.graph_rev[to].append(fr)

    def dfs(self, node, graph):
        self.used[node] = True
        for nex in graph[node]:
            if self.used[nex]:
                continue
            self.dfs(nex,graph)
        self.order.append(node)

    def first_dfs(self):
        self.used = [False]*self.n
        self.order = []
        for i in range(self.n):
            if self.used[i]:
                continue
            self.dfs(i,self.graph)
    
    def second_dfs(self):
        self.used = [False]*self.n
        self.ans = []
        for node in reversed(self.order):
            if self.used[node]:
                continue
            self.used[node] = True
            self.order = []
            self.dfs(node, self.graph_rev)
            #self.order.reverse()
            self.ans.append(self.order)

    def scc(self):
        self.first_dfs()
        self.second_dfs()
        return self.ans
        
def main():
    n,m = map(int,input().split())
    scc = SCC(n)
    for _ in range(m):
        a,b = map(int,input().split())
        scc.add_edge(a,b)

    ans = scc.scc()

    print(len(ans))
    for i in ans:
        print(len(i),*i)

if __name__ == "__main__":
    main()

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

using namespace std;

#define endl "\n"


const int INF = 1e5+ 5;

vector<int> edges[INF];
vector<int> dist(INF);
vector<bool> visited(INF, false);
vector<int> in_degree(INF);

void dfs(int a) {
	visited[a] = true;
	for(auto i : edges[a]) {
		dist[i] = max(dist[i], dist[a] + 1);
		--in_degree[i];
		if(in_degree[i] == 0) 
			dfs(i);
	}
}

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

    int N, M;
	cin >> N >> M;
	
	while(M--) {
		int a, b;
		cin  >> a >> b;
		edges[a].push_back(b);
		++in_degree[b];
	}

	for(int i = 1; i <=  N; i++) {
		if(!visited[i] && in_degree[i] == 0) {
			dfs(i);
		}
	}

	int answer = 0;
	for(int i = 1; i <= N; i++) {
	 	answer = max(answer, dist[i]);
	 }
	cout << answer << endl;
    return 0;
}


Measured memory_bytes: 14212
#include <bits/stdc++.h>
#include <iostream>
#include <string>

#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define phi 3.1415926535
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
 
using namespace std;

const ll mod = 1000000007;    

ll tc, cnt = 0, number, many, total = 0, query;
// vector <vector <int> > adjList;
int rmove[8] = {-1, 0, 1, 0, -1, 1, -1, 1};
int cmove[8] = {0, 1, 0, -1, 1, -1, -1, 1};

ll power(ll x, ll y, ll mod)
{
    if(y == 0)
        return 1;
    else if(y % 2 == 0)
        return (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
    else
        return x * (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
}

int main()
{
    fastio();
        
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // g++ -std=c++11 Default.cpp  -o test
    // g++ -Wl,--stack=268435456 -std=c++11 Default.cpp  -o test

    cin >> many;

    int arr[many];
    for(int i = 0; i < many; i++)
        cin >> arr[i];

    int dp[many];
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;

    for(int i = 0; i < many; i++)
    {
        for(int j = i + 1; j <= i + 2 && j < many; j++)
        {
            if(dp[j] == -1)
                dp[j] = dp[i] + abs(arr[j] - arr[i]);
            else
                dp[j] = min(dp[i] + abs(arr[j] - arr[i]), dp[j]);
        }
    }

    // for(int i = 0; i < many; i++)
    //     cout << dp[i] << " ";
    // cout << endl;

    cout << dp[many - 1] << endl;

    //
    return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

bool kaibun(string s){
    string t=s;
    reverse(t.begin(), t.end());
    return s==t;
}

int main(){
    string s;
    cin >> s;
    int n = s.length()/2;
    if(kaibun(s) and kaibun(s.substr(0, n)) and kaibun(s.substr(n+1, n))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



string niz[] = {"AC", "WA", "TLE", "RE"};
map<string,int>poj;


int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    int t;
    cin >> t;
    while(t --){
        string x;
        cin >> x;
        poj[x]++;
    }
    ff(i,0,3){
        cout << niz[i] << " x " << poj[niz[i]] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3672
n, p = map(int, input().split())
s = input()

ans = 0
mod = [-1 for i in range(p)]
mod[0] = 0

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    mp = 0
    m10 = 1
    for i in range(n-1, -1, -1):
        m10 = (10 * m10) % p
        mp = (mp + int(s[i]) * m10) % p
        mod[mp] += 1

    for m in mod:
        ans += m*(m+1)//2

print(ans)

Measured memory_bytes: 3500
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n;
string s;
int q,k;

int main()
{
  scanf("%d",&n);
  s = GetString();
  scanf("%d",&q);
  TC(q)
  {
    scanf("%d",&k);
    LL risan = 0;
    LL now = 0;
    int nowm = 0;
    int nowc = 0;
    FORD(i,n-1,0)
    {
      int loss = i + k;
      if (loss < n)
      {
        if (s[loss] == 'C')
        {
          --nowc;
          now -= nowm;
        }
        if (s[loss] == 'M') --nowm;
      }
      if (s[i] == 'D') risan += now;
      if (s[i] == 'M') 
      {
        now += nowc;
        ++nowm;
      }
      if (s[i] == 'C')
      {
        ++nowc;
      }
    }
    printf("%lld\n",risan);
  }
  return 0;
}











Measured memory_bytes: 2176
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	
	int n, a, b, c, x;
	cin>> n>> a>> b>> c>> x;
	if(n==0 && a==0 && b==0 && c==0 && x==0) return false;
	vector<int> y(n);
	for(int i=0;i<n;i++){
		int in;
		cin>> in;
		y[i] = in;
	}

	int cnt = 0;
	int flag = 0;
	int ans;
	for(int i=0;i<10001;i++){			//10001だった
		if(y[cnt] == x) cnt++;
		if(cnt==n){
			ans = i;
			flag++;
			break;
		}
		x = (a * x + b) % c;
	}
	
	if(flag){
		cout<< ans<< endl;
	}else{
		cout<< -1<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	while(solve());

	return 0;
}

 

Measured memory_bytes: 1196