akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

bool used[101];

signed main(){
    int x, n; cin >> x >> n;
    REP(i,101)used[i] = false;
    REP(i,n){
        int p; cin >> p;
        used[p] = true;
    }
    if(!used[x]){
        cout << x << endl;
        goto end;
    }
    REPS(i,100){
        if(!used[x-i]){
            cout << x-i << endl;
            goto end;
        }
        if(!used[x+i]){
            cout << x+i << endl;
            goto end;
        }
    }
    end:;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>

using namespace std;

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

int main(){
	int ans=0,n;
	cin >> n;
	vector<int> v,c;

	REP(i,n){
		int a;
		cin >> a;
		v.push_back(a);
	}

	REP(i,n){
		int a;
		cin >>a;
		c.push_back(a);
	}

	REP(i,n)if(v[i]>c[i])ans+=(v[i]-c[i]);

	cout << ans << endl; 

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> A(N, 0);
  for(auto &i : A) cin >> i;
  bool flag = true;
  REP(i, N){
    if(A[i] % 2 == 0){
      if(A[i] % 3 == 0 || A[i] % 5 == 0){
        continue;
      }else{
        flag = false;
        break;
      }
    }
  }
  if(flag){
    cout << "APPROVED" << endl;
  }else{
    cout << "DENIED" << endl;
  }
}

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

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

  if (s.size()<=k) cout << s << endl;
  else {
    string t="";
    for (int i=0;i<k;++i) t.push_back(s[i]);
    cout << t << "..." << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main() {
    int n, maxProfit, cur, min, minI = 0, temp;

    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%d", &cur);

        if (i == 0)
            min = cur;
        else
            temp = cur - min;

        if (cur < min) {
            min = cur;
            minI = i;
        }

        if (i == 1)
            maxProfit = temp;
        else {
            if (temp > maxProfit && i != 0)
                maxProfit = temp;
        }
    }

    printf("%d\n", maxProfit);
    return 0;
}


Measured memory_bytes: 2080
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {

  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);

    int n = in.nextInt();
    int k = in.nextInt();
    boolean[] hasSnack = new boolean[n+1];
    while (k-- > 0) {
      int dk = in.nextInt();
      while (dk-- > 0) {
        hasSnack[in.nextInt()] = true;
      }
    }
    int count = 0;
    for (boolean val: hasSnack) {
      if (!val) count++;
    }
    System.out.println(count-1);
  }

  static class InputReader {

    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int snext() {
      if (snumChars == -1) throw new InputMismatchException();
      if (curChar >= snumChars) {
        curChar = 0;
        try {
          snumChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (snumChars <= 0) return -1;
      }
      return buf[curChar++];
    }

    public int nextInt() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = snext();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = snext();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public long nextLong() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = snext();
      }
      long res = 0;
      do {
        if (c < '0' || c > '9') throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = snext();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public int[] nextIntArray(int n) {
      int a[] = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = nextInt();
      }
      return a;
    }

    public String readString() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      StringBuilder res = new StringBuilder();
      do {
        res.appendCodePoint(c);
        c = snext();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public String nextLine() {
      int c = snext();
      while (isSpaceChar(c)) c = snext();
      StringBuilder res = new StringBuilder();
      do {
        res.appendCodePoint(c);
        c = snext();
      } while (!isEndOfLine(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) return filter.isSpaceChar(c);
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private boolean isEndOfLine(int c) {
      return c == '\n' || c == '\r' || c == -1;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);
    }
  }
}


Measured memory_bytes: 32444
// 0128
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

void abacus(int num[]){
	for(int j=0;j<2;j++){
		for(int i=0;i<5;i++)
			if((5*j <= num[i]) && (num[i] < 5*(j+1)))
				cout<<"*";
			else
				cout<<" ";
		cout<<endl;
	}

	for(int i=0;i<5;i++)
		cout<<"=";
	cout<<endl;

	for(int j=0;j<5;j++){
		for(int i=0;i<5;i++)
			if(num[i]%5 == j)
				cout<<" ";
			else
				cout<<"*";
		cout<<endl;
	}
}

int main(){

	int n, count = 0;
	while(scanf("%d", &n) != EOF){
		if(count != 0)
			cout<<endl;

		int num[5];
		for(int i=0;i<5;i++){
			num[4-i] = n%10;
			n /= 10;
		}
		
		abacus(num);

		count++;
	}

	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define dans(ans) cout << std::fixed << std::setprecision(10) << ans << endl;
main()
{
    int n;
    cin>>n;
    set<int>st;
    vector<int>v(n);
    map<int,int>cnt;
    int total=0;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        st.insert(x);
        v[i]=x;
        cnt[x]++;

    }
    for(auto it:st)
    {
        total+=(cnt[it]*(cnt[it]-1))/2;
    }
    for(int i=0; i<n; i++)
    {
        int x,y,ans=total;
        x=cnt[v[i]];
        ans-=(x*(x-1))/2;
        x--;
        ans+=(x*(x-1))/2;
        cout<<ans<<endl;
    }
}
/// check long long
/// check array size()



Measured memory_bytes: 18492
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m;
int a[100005];
int pre[100005];
map<int,int>mp;
signed main(){
	cin>>n>>m;
	mp[0]++;
	for(int i=1;i<=n;i++)cin>>a[i],pre[i]=pre[i-1]+a[i],mp[pre[i]%m]++;
	int ans=0;
	for(auto p:mp){
		ans+=p.second*(p.second-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5760
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd

sys.setrecursionlimit(10**7)
x1, y1, x2, y2 = map(int, input().split())

v1 = x2 - x1, y2 - y1
v2 = -v1[1], v1[0]
v3 = -v2[1], v2[0]

x3, y3 = x2 + v2[0], y2 + v2[1]
x4, y4 = x3 + v3[0], y3 + v3[1]

print(x3, y3, x4, y4)


Measured memory_bytes: 38256
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#include<fstream>
#define f first
#define s second
#define MOD 1000000007

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define BOUNDARY(i, j) ((i >= 0 && i < rows) && (j >= 0 && j < coloums))

//#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
const ll maxn = 2*100005;
using namespace std;
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
int rows,coloums;
long long  gcd(long long  a, long long b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main(){
    fast;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    while(1)
    {
        c = c-b;
        if (c<=0){
            cout<<"Yes"<<endl;
            break;
        }
        a = a-d;
        if(a<=0){
            cout<<"No"<<endl;
            break;
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    cin >> N;
    if(N==3) cout << "2 5 63" << endl;
    else if(N==4) cout << "2 5 20 63" << endl;
    else{
        cout << "2 3 4 9";
        N-=4;
        for(int i=8;i+2<30000 && N>=2;i+=6){
            cout << " " << i << " " << i+2;
            N-=2;
        }
        for(int i=15;i+6<30000 && N>=2;i+=12){
            cout << " " << i << " " << i+6;
            N-=2;
        }
        for(int i=6;N>0;i+=6){
            cout << " " << i;
            N--;
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
using System;

namespace ABC122
{
    class B
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();

            int count = 0;
            int tmp = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
                {
                    tmp++;
                }
                else
                {
                    tmp = 0;
                }
                count = Math.Max(count, tmp);
            }
            Console.WriteLine(count);
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

void divisor(vector<int> &v, int n) {
    for(int i = 1; i*i <= n; i++) {
        if(n % i == 0) {
            v.push_back(i);
            if(i*i != n) v.push_back(n/i);
        }
    }
    sort(all(v));
}

signed main(){
    int N, M;
    cin >> N >> M;
    vector<int> div;
    divisor(div, M);
    sort(rall(div));
    
    for(int i: div){
        if(M/i >= N){
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL  
struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};

typedef struct node * Node;
Node root;
Node find(Node u, int k);
void insert(int k);
void inorderTreeWalk(Node x);
void preorderTreeWalk(Node x);
  
int main()
{
  char str[7];
  int m,i,x,key;
  scanf("%d",&m);
  for( i=0 ; i<m ; i++ ){
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(str[0]=='p'){
      inorderTreeWalk(root);
      printf("\n");
      preorderTreeWalk(root);
      printf("\n");
    }
    else{
      scanf("%d",&key);
      if( find(root,key)==NIL ){
	printf("no\n");
      }else{
	printf("yes\n");
      }   
    }
  }
  return 0;
   
}
Node find(Node u, int k){
      if( u == NIL || k == u->key ){
          return u;
      }  
      if( k < u->key ){
        return find(u->l,k);
      }else{
        return find(u->r,k);
      }
}

void insert(int k)
{
  Node x;
  Node y;
  Node z;
  y = NIL;
  x = root;
  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
   
  while(x!=NIL){
    y=x;
    if(z->key<x->key) x = x->l;
    else x = x->r;
  }
  z->p = y;
 
  if(y==NIL) root = z;
  else if(z->key<y->key) y->l = z;
  else y->r = z;
}
 
void inorderTreeWalk(Node x)
{
  if(x==NIL) return;
  inorderTreeWalk(x->l);
  printf(" %d",x->key);
  inorderTreeWalk(x->r);
}
 
void preorderTreeWalk(Node x)
{
  if(x==NIL) return;
    printf(" %d",x->key);
    preorderTreeWalk(x->l);
    preorderTreeWalk(x->r);
   
}

Measured memory_bytes: 19364
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 10010, D = 110, P = 1000000007;

int d;
char s[N];
int dp[D], tmp[D];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%s%d", s + 1, &d);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; ++i)
    s[i] -= '0';
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    memset(tmp, 0, sizeof(tmp));
    for (int j = 0; j < d; ++j)
      for (int v = 0; v < 10; ++v)
        if ((tmp[(j + v) % d] += dp[j]) >= P)
          tmp[(j + v) % d] -= P;
    for (int x = 0; x < s[i]; ++x)
      if (++tmp[(sum + x) % d] == P)
        tmp[(sum + x) % d] = 0;
    sum = (sum + s[i]) % d;
    memcpy(dp, tmp, sizeof(dp));
  }
  int ans = dp[0];
  if (sum == 0)
    if (++ans == P)
      ans = 0;
  if (--ans < 0)
    ans = P - 1;
  printf("%d\n", ans);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
import sys
import collections
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = []
C = []

A_collections = collections.Counter(A)
sum_A = sum(A)

for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(Q):
    b, c = B[i], C[i]
    if b in A_collections.keys():
        A_collections[c] += A_collections[b]
        sum_A += (c - b) * A_collections[b]
        A_collections[b] = 0
    
    print(sum_A)


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 == 0 && s == s.substr(n / 2) + s.substr(n / 2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3628
/*input
5 3 5
1
2
3
6
12
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int a[maxn];

int main(){
	IOS;
	int n,c,k;
	cin>>n>>c>>k;
	REP(i,n) cin>>a[i];
	sort(a,a+n);
	int ans=0;
	int cc=0,t=-INF;

	for(int i=0;i<n;i++){
		if(cc==0||a[i]-t>k){
			// cout<<i<<'\n';
			ans++;
			t=a[i];
			cc=c-1;
		}
		else{
			cc--;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<complex>
#include<cmath>
using namespace std;
typedef complex<double> xy_t;

int n;
double x,y;
xy_t abcd[4];
const double eps=1e-11;

double cross_product(xy_t a,xy_t b){ //クロス積
    return (conj(a)*b).imag();
}


int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            cin>>x>>y;
            abcd[j]=xy_t(x,y);
        }
        bool p=abs(cross_product(abcd[0]-abcd[1],abcd[2]-abcd[3]))<eps; //面積がepsより小さいか
        if(p){cout<<"YES"<<endl;}
        else{cout<<"NO"<<endl;}
    }
}


Measured memory_bytes: 3152
c = input()
data = []
for s in range(0,int(c)):
  data.append(list(map(int, input().split())) )

nexttime = 0
nextx = 0
nexty = 0


for s in range(0, len(data)):
  nexttime = data[s][0]
  nextx = data[s][1]
  nexty = data[s][2]
  if ( (nexttime < nextx+nexty) or ((((nextx + nexty) ) % 2) != (nexttime % 2) ) ):
    print("No")
    exit()


print("Yes")


Measured memory_bytes: 27400
main :: IO ()
main = unwords . split <$> getLine >>= putStrLn

split = _split []
_split ts "" = ts
_split ts s = _split (ts ++ [(token s)]) (drop (length(token s) + 1) s)
token = _token ""
_token ys "" = ys
_token ys (x:xs) = do
if x == ','
then ys
else _token (ys ++ [x]) xs


Measured memory_bytes: 380
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>

int main(){
    int N;
    std::cin >> N;
    std::vector< std::string > S(N);
    for(int i=0; i<N;i++){
        std::cin >> S[i];
    }
    
    std::sort(S.begin(), S.end());
    
    int cnt = 0, maxcnt = 0;
    std::string tmp;
    std::deque < std::string > out;
    for(int i=0; i<N;i++){
        if(cnt == 0){
            tmp = S[i];
            cnt = 1;
        }else{
            if(S[i] == tmp){
                cnt++;
            }else{
                if(cnt > maxcnt){
                    out.clear();
                    out.push_back(tmp);
                    maxcnt = cnt;
                }else if(cnt == maxcnt){
                    out.push_back(tmp);
                }
                tmp = S[i];
                cnt = 1;
            }
        }
        if(i == N - 1){
            if(cnt > maxcnt){
                out.clear();
                out.push_back(tmp);
                maxcnt = cnt;
            }else if(cnt == maxcnt){
                out.push_back(tmp);
            }
        }
    }
    

    for(int i=0; i<out.size(); i++){
        std::cout << out[i] << std::endl;
    }
}


Measured memory_bytes: 15872
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    D = [tuple(map(int, input().split())) for _ in [0] * N]  # [(1, 2), (3, 4)]

    n = 0
    for d1, d2 in D:
        if d1 == d2:
            n += 1
        else:
            n = 0
        if n > 2:
            print('Yes')
            break
    else:
        print('No')


main()


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
typedef long long ll;
typedef long double ld;
long long dx[] = {1,0,-1,0};
long long dy[] = {0,1,0,-1};
long long dx8[] = {1,1,0,-1,-1,-1,0,1};
long long dy8[] = {0,1,1,1,0,-1,-1,-1};
long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};

struct BinaryIndexedTree{
    vector<vector<long long>> BIT;
    BinaryIndexedTree(vector<long long> A) : BIT(){
        int n;
        while((1<<n)<=A.size())n++;
        BIT.resize(n);
        while(A.size()<(1<<n)-1)A.push_back(0);
        for(int i = 0;i < n;i++)BIT[i].resize(1<<(n-i-1));
        for(int i = 1;i < A.size();i++)A[i] += A[i-1];
        for(int i = 0;i < n;i++){
            for(int j = 0;j < BIT[i].size();j++){
                BIT[i][j] = A[(1<<(i))-1+(1<<(i+1))*j] - (j ? A[(1<<(i+1))*j-1] : 0);
            }
        }
    }
    long long get(long long i){
        long long ans = 0;
        long long n = 0;
        while(n < BIT.size()){
            if(i%2 == 0){
                ans += BIT[n][(i>>1)];
                i--;
            }
            i >>= 1;
            n++;
        }
        return ans;
    }
    long long getSum(long long x,long long y){
        return get(y) - (x ? get(x-1) : 0);
    }
    void add(long long i,long long x){
        long long n = 0;
        while(n < BIT.size()){
            if(i%2 == 0){
                BIT[n][(i>>1)] += x;
            }
            i >>= 1;
            n++;
        }
    }
};

signed main(){
    int n,q;
    cin >> n >> q;
    BinaryIndexedTree bit(vector<ll>(n,0));
    FOR(rep,0,q){
        ll com,x,y;
        cin >> com >> x >> y;
        if(!com){
            x--;
            bit.add(x,y);
        }
        else{
            x--;y--;
            cout << bit.getSum(x,y) << endl;
        }
    }
}


Measured memory_bytes: 4852
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll pow(ll a, ll b, ll m) {
    ll res = 1;
    for (a %= m; b; b >>= 1, (a *= a) %= m)
        if (b & 1) (res *= a) %= m;
    return res;
}
ll n, m, a, b, ans, f[200005];
ll inv(ll x) {
    return pow(x, mod - 2, mod);
}
ll C(ll n, ll k) {
    return f[n] * inv(f[n-k]) % mod * inv(f[k]) % mod;
}
ll calc(ll n, ll m) {
    return C(n + m, m);
}
int main() {
    cin >> n >> m >> a >> b; f[0] = 1;
    for (ll i = 1; i <= n + m - 2; ++i)
        f[i] = f[i-1] * i % mod;
    for (ll i = b + 1; i <= m; ++i) {
        (ans += calc(n - a - 1, i - 1) % mod * calc(a - 1, m - i)) %= mod;
    }
    ans = (ans % mod + mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	var r, g, b, n int
	fmt.Scan(&r, &g, &b, &n)
	sum := 0
	for i := 0; i <= n; i++ {
		for j := 0; j <= n; j++ {
			v := n - i*r - j*g
			if 0 <= v && v%b == 0 {
				sum++
			}
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d",res);
#define pfl(res) printf("%lld",res);
#define pfd(res) printf("%lf",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];

int main()
{
    int n;
    sc(n);
    for(int i=1;i<=n;i++)
    {
        sc(arr[i]);
    }
    arr[0]=9999999;
    for(int i=2;i<=n;i++)
    {
        int x=abs(arr[i]-arr[i-1])+arr2[i-1];
        int y=abs(arr[i]-arr[i-2])+arr2[i-2];
        arr2[i]=min(x,y);
        //cout<<arr2[i]<<endl;
    }
    cout<<arr2[n];

}






Measured memory_bytes: 1024
n = int(input())
a = [0] + [int(input()) for i in range(n)]
c = a[1]
p = 1
while c > 2:
    d = a[c]
    a[c] = 0
    c = d
    p += 1

if c == 2:
    print(p)
else:
    print(-1)


Measured memory_bytes: 7852
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
ll dp[1000002];
int main(){
  ll a,b,c;cin>>a>>b>>c;
  ll d=a/b;
  if(a%b!=0)d++;
  cout<<d*c;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;
int add(int &a, int b) { return (a += b) >= MOD ? a -= MOD : a; }

int main() {
    int N; cin >> N;
    vector<vector<int>> a(N, vector<int>(N));
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> a[i][j];

    vector<vector<int>> dp(N + 1, vector<int>(1 << N, 0));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) for (int s = 0; s < 1 << N; s++) if (dp[i][s]) {
        for (int j = 0; j < N; j++) if (!(s & (1 << j)) && a[i][j]) {
            add(dp[i + 1][s | (1 << j)], dp[i][s]);
        }
    }
    cout << dp[N][(1 << N) - 1] << endl;
    return 0;
}

Measured memory_bytes: 188800
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		List<String> list = new ArrayList<String>();
		while (true) {
			String line = sc.nextLine();
			if (line.equals("0")) {
				break;
			}
			list.add(line);
		}

		int i = 1;
		for (String line : list) {
			int x = Integer.parseInt(line);
			System.out.println("Case " + i + ": " + x);
			i++;
		}

	}
}

Measured memory_bytes: 61860
prime = [True for i in range(200001)]
prime[0] = False
prime[1] = False
p = 2
while p * p <= 200000:
    if prime[p]:
        for i in range(p * 2, 200001, p):
            prime[i] = False
    p += 1

while True:
    N, P = map(int, input().split())
    if N < 0:
        exit()
    li = []
    for i in range(N + 1, N + 10001):
        if prime[i]:
            li.append(i)
    li.sort()
    ans = []
    for i in range(100):
        for j in range(i, 100):
            ans.append(li[i] + li[j])
    print(sorted(ans)[P - 1])



Measured memory_bytes: 7276
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
vector<vector<char> >v(101,vc(101,0));
int h,w,ans;
int mx[]={0,0,1,-1};
int my[]={1,-1,0,0};
void dfs(int y,int x,char now){
    v[y][x]='$';
    rep(i,4){
        int tx=x+mx[i]; int ty=y+my[i];
        if(0<=tx&&tx<w&&0<=ty&&ty<h&&v[ty][tx]==now)dfs(ty,tx,now);
    }
}
int main(){
    while(cin>>h>>w,h+w){
        ans=0;
        rep(i,h)rep(j,w)cin>>v[i][j];
        rep(i,h)rep(j,w){if(v[i][j]!='$'){ans++;dfs(i,j,v[i][j]);}}
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int L, R, tmp, mini=2019;
  cin >> L >> R;
  
  for(int i=0 ; i < 1.0e+6 ; i++){
    if(2019*i >= L){
      tmp = i;
      break;
    }
  }
  
  if(2019*tmp <= R)
    cout << 0 << endl;
  else{
    for(long int i=L; i<R;i++){
      for(long int j=i+1; j<=R;j++){
        mini = min((i*j)%2019,mini);
      }
    }
          cout << mini << endl;
  }

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String s = br.readLine();
            int a = 0;
            int z = 0;
            for (int i = 0; i < s.length(); i++) {
                String tmp = s.substring(i, i + 1);
                if ("A".equals(tmp)) {
                    a = i;
                    break;
                }
            }
            for (int i = s.length(); i > 0; i--) {
                String tmp = s.substring(i - 1, i);
                if ("Z".equals(tmp)) {
                    z = i;
                    break;
                }
            }
            System.out.println(z - a);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 20304
def main():
    n = int(input())
    l = sorted(list(map(int,input().split())))
    ans = 0
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if l[i]!=l[j] and l[j]!=l[k]:
                    if l[k]<l[i]+l[j]:
                        ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[] line = new int[w];
		Arrays.fill(line, Integer.MAX_VALUE);
		int max = 0;
		for (int i = 0; i < h; i++) {
		    char[] arr = sc.next().toCharArray();
		    for (int j = 0; j < w; j++) {
		        if (arr[j] == '.') {
		            continue;
		        }
		        for (int k = 0; k < w; k++) {
		            if (line[k] != Integer.MAX_VALUE) {
		                max = Math.max(max, Math.abs(j - k) + i - line[k]);
		            }
		        }
		        if (line[j] == Integer.MAX_VALUE) {
		            line[j] = i;
		        }
		    }
		}
		System.out.println(max);
	}
}



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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	map<int, int> p;
	for( int i = 1; i <= N; ++i ) {
		int x = i;
		int y = 2;

		while( x > 1 ) {
			if( x % y ) {
				y += 1;
			}
			else {
				p[y] += 1;
				x /= y;
			}
		}
	}

	int64_t result = 1;
	int64_t m = 1000000007;

	for( auto& v: p ) {
		result = result * (v.second + 1) % m;
	}

	cout << result << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#define MAXN 510000
#define INF 2147483647
#define ls now*2
#define rs now*2+1
using namespace std;
int n,k;
int sit[MAXN],val[MAXN];
int tree[MAXN*4];
int in[MAXN],next[MAXN*2],head[MAXN],to[MAXN*2];
int ans[MAXN];
inline int read(){
    int x = 0 , f = 1 ; char c = getchar();
    while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
    while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
    return x * f ;
}

inline void up(int now){
	tree[now]=min(tree[now],min(tree[ls],tree[rs]));
}

void change(int now,int l,int r,int sit,int val){
	if (l==r){
		tree[now]=min(tree[now],val);
		return;
	}
	int mid=(l+r)/2;
	if (sit<=mid) change(ls,l,mid,sit,val);
	else change(rs,mid+1,r,sit,val);
	up(now);
}

int ask(int now,int l,int r,int ll,int rr){
	if (l>=ll&&r<=rr){
		return tree[now];
	}
	int mid=(l+r)/2,tmp=INF;
	if (ll<=mid) tmp=min(tmp,ask(ls,l,mid,ll,rr));
	if (rr>mid) tmp=min(tmp,ask(rs,mid+1,r,ll,rr));
	return tmp;
}

int cnt=0;
void link(int u,int v){
	cnt++;
	to[cnt]=v;
	next[cnt]=head[u];
	head[u]=cnt;
	in[v]++;
}

priority_queue<int, vector<int>, greater<int> > q;
void topo(){
	int cnt=0;
	for(int i=1;i<=n;i++)
		if (!in[i]) q.push(i);
	while(!q.empty()){
		int now=q.top();
		q.pop();
		ans[now]=++cnt;
		for(int i=head[now];i;i=next[i]){
			in[to[i]]--;
			if (!in[to[i]])
				q.push(to[i]);
		}
	}
}
	
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		val[i]=read();
		sit[val[i]]=i;
	}
	fill(tree+1,tree+4*MAXN,INF);
	for(int i=n;i>=1;i--){
		int v;
		if (sit[i]!=n){
			v=ask(1,1,n,sit[i]+1,min(sit[i]+k-1,n));
			if (v!=INF)
				link(sit[i],sit[v]);
		}
		if (sit[i]!=1){
			v=ask(1,1,n,max(sit[i]-k+1,1),sit[i]-1);
			if (v!=INF)
				link(sit[i],sit[v]);
		}
		change(1,1,n,sit[i],i);
	}
	topo();
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
	return 0;
}

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

int main(){
	int m, f, r,sum;
	string point;

	for (;;){
		cin >> m >> f >> r;
		sum = m + f;
		if (m == -1 && f == -1 && r == -1){
			break;
		}
		if (m == -1 || f == -1){
			point = "F";
		}
		else if (r >= 50){
			point = "C";
		}
		else if (sum >= 80){
			point = "A";
		}
		else if (sum >= 65){
			point = "B";
		}
		else if (sum >= 50){
			point = "C";
		}
		else if (sum >= 30){
			point = "D";
		}
		else {
			point = "F";
		}
		cout << point << endl;

	}
	cin >> m;
}


Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int aru = 0;
  int kotae = 1000000;
  for(int i = a  * 100 / 8;i <= (b + 1) * 100 / 10;i++){
    if(i * 8 / 100 == a && i * 10 / 100 == b){
      aru = 1;
      if(kotae >= i){
      kotae = i;
      }
    }
  }
  if(aru == 0){
    cout << -1 << endl;
  }
  else{
    cout << kotae << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
int main()
{
	// freopen("AGC012-F.in", "r", stdin);
	int n;
	cin >> n;
	vector<int> arr(2 * n - 1);
	copy(istream_iterator<int>(cin), istream_iterator<int>(), arr.begin());
	sort(arr.begin(), arr.end());
	int m = arr.size();
	vector<vector<int> > dp(m + 5, vector<int>(m + 5, 0));
	dp[0][0] = 1;
	for (int i = n - 1; i; i--) {
		vector<vector<int> > nxt(m + 5, vector<int>(m + 5, 0));
		bool a = arr[i] != arr[i - 1], b = arr[m - i] != arr[m - i - 1];
		for (int j = 0; j <= m; j++) {
			for (int k = 0; k <= m; k++) {
				(nxt[j + a][k + b] += dp[j][k]) %= p;
				for (int x = 0; x < j + a; x++) {
					(nxt[x][k + b + 1] += dp[j][k]) %= p;
				}
				for (int x = 0; x < k + b; x++) {
					(nxt[j + a + 1][x] += dp[j][k]) %= p;
				}
			}
		}
		dp = nxt;
	}
	int ans = 0;
	for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= m; j++) {
			(ans += dp[i][j]) %= p;
		}
	}
	cout << ans % p << endl;
	return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long[] f;
        static void Main(string[] args)
        {
            var Q = Sarray()[0];
            for (var i = 0; i < Q; ++i)
            {
                var len1 = ReadLine();
                var len2 = ReadLine();
                var w = len1.Length;
                var h = len2.Length;
                var mtch = new int[w, h];
                for (var j = 0; j < w; ++j)
                {
                    for (var k = 0; k < h; ++k)
                    {
                        if (len1[j] == len2[k])
                        { mtch[j, k] = 1; }
                    }
                }
                var rui = new int[w + 1, h + 1];
                for(var j=1;j<w+1;++j)
                {
                    for (var k = 1; k < h + 1; ++k)
                    {
                        rui[j, k] = Math.Max(Math.Max(rui[j - 1, k], rui[j, k - 1]), rui[j - 1, k - 1] + mtch[j - 1, k - 1]);
                    }
                }
#if DEBUG
                for (var j = 0; j < w; ++j)
                {
                    for (var k = 0; k < h; ++k)
                    {
                        Write(mtch[j, k]+", ");
                    }
                    WriteLine();
                }
                for (var j = 0; j < w+1; ++j)
                {
                    for (var k = 0; k < h+1; ++k)
                    {
                        Write(rui[j, k] + ", ");
                    }
                    WriteLine();
                }
#endif
                WriteLine(rui[w, h]);
            }
        }
    }
}


Measured memory_bytes: 41216
#include<iostream>
#include<string>
#define LL long long
#define INF 0x3f3f3f3f
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=2e5+100;
using namespace std;	
pair<LL,LL>a[N];
int main()
{
	int n;
	while(cin>>n)
	{
		for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second;
		if(a[1].first==a[1].second)a[1].first=a[1].second=1;
		for(int i=2;i<=n;i++)
		{
			LL tmp=max((a[i-1].first-1)/a[i].first+1,(a[i-1].second-1)/a[i].second+1);
			a[i].first*=tmp;
			a[i].second*=tmp;
		}
		cout<<a[n].first+a[n].second<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <set>
#include <map>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;
using VP = vector<P>;

int main() {
    long n;
    cin >> n;
    VI v;
    REP(i,n) {
        long a;
        cin >> a;
        v.push_back(a);
    }
    VI w(v);
    sort(w.begin(), w.end());
    long sm = w[n/2-1];
    long bm = w[n/2];
    
    REP(i,n) {
        if (v[i] >= bm) {
            cout << sm << endl;
        } else {
            cout << bm << endl;
        }
    }
}


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

using namespace std;
using ll = long long;
int kaij(int n) {
    if(n == 1) {
        return 1;
    }
    return n*kaij(n - 1);
}

int main() {
    int N = 0;
    cin >> N;
    vector<int> x(N,0);
    vector<int> y(N,0);
    for(int i = 0; i < N; i++) {
        cin >> x.at(i);
        cin >> y.at(i);
    }
    double sum = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N && j != i; j++) {
            sum += pow(pow(x.at(i) - x.at(j),2) + pow(y.at(i) - y.at(j),2),0.5);
        }
    }
    cout << fixed << setprecision(10) << sum*2/N << endl;

    return 0;
}

//N*(N - 1)    N!*(N - 1)

Measured memory_bytes: 4204
# 解答AC

x,y = map(int, input().split())

ans = float("inf")
for B1 in range(2):
    x2 = -x if B1 else x
    for B2 in range(2):
        y2 = -y if B2 else y
        if x2 <= y2:
            ans = min(ans, y2 - x2 + B1 + B2)

print(ans)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int calc(int x) {
	int ret = 0;
	while(x % 100 == 0)
		x /= 100, ++ret;
	return ret;
}
int main() {
	int D, N;
	cin >> D >> N;
	int cnt = 0, val = 0;
	while(cnt < N) {
		++val;
		if(calc(val) == D) ++cnt;
	}
	cout << val << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	string str;
	while(cin>>str){
	int i,ioi=0,joi=0;
	for(i=0;i<str.size()-2;i++){
		if(str.substr(i,3)=="JOI")joi++;
		if(str.substr(i,3)=="IOI")ioi++;
	}
	cout<<joi<<endl<<ioi<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
from collections import defaultdict

def main():
    lines = sys.stdin.readlines()
    n, m = map(int, lines[0].split())
    relation_lines = lines[1:1+m]

    relations = defaultdict(list)

    for idx, relation_line in enumerate(relation_lines):
        s, t = relation_line.split()
        relations[s].append(t)
        relations[t].append(s)

    group = {}
    for key in relations.keys():
        group[key] = -1
    group_num = 0

    # assign a group number for ids
    for key, val in relations.items():
        if group[key] != -1:
            continue

        group[key] = group_num
        group_num += 1

        group_no = group[key]
        friends = [key]

        while len(friends) != 0:
            n_fs = relations[friends.pop()]
            for n_f in n_fs:
                if group[n_f] == -1:
                    group[n_f] = group_no
                    friends.append(n_f)

    q = int(lines[1+m])
    question_lines = lines[1+m+1:]
    answers = [None] * q
    for i, question in enumerate(question_lines):
        s, t = question.split()

        if s not in group or t not in group:
            answers[i] = 'no'
            continue
        elif group[s] == group[t]:
            answers[i] = 'yes'
        else:
            answers[i] = 'no'

    # answer
    [print(ans) for ans in answers]
    return

main()


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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define all(a) a.begin(), a.end()

template <typename T>
T Sum(vector<T> n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}
template <>
ld Sum(vector<ld> n, ll a, ll b)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i] >> p[i];
  }
}

void fYn(bool a)
{
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  exit(0);
}
//最大公約数
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
//最小公倍数
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}
//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}

//大文字->小文字(+32)
//少数はなるべく整数に

void Main()
{
  ll n; cin >> n;
  vll a(n); V(a);
  ll top = nlcm(a), sum = 0;
  rep(i, n) sum += top / a[i];
  fin(top * 1. / sum);
}

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

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++)
            p[i] = sc.nextInt();
        
        int count = 0;

        for (int i = 1; i < n-1; i++){
            if (((p[i-1] < p[i]) && (p[i] < p[i+1])) ||
                ((p[i-1] > p[i]) && (p[i] > p[i+1])))
                count++;
        }
        System.out.println(count);
        sc.close();
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const lli inf=1e18;
const int mod=1e9+7;
int main(){
IOS;
string s;
cin>>s;
int count=0,n=s.length();
for(int i=0;i<n/2;i++){
    if(s[i]!=s[n-i-1])
        count++;
}
cout<<count<<endl;
}


Measured memory_bytes: 256
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
s = l()
c = 0
d = 0
for i in range(len(s)):
    if i%2 == 0 and s[i] == "h":
        c += 1
    else:
        if s[i] == "i":
            d += 1
print("Yes" if c == d and len(s) == c+d else "No")

Measured memory_bytes: 3064
def d_non_decreasing(N, A):
    from numpy import argmax, argmin
    a = A[:]
    a_max = max(a)
    a_argmax = argmax(a) + 1
    a_min = min(a)
    a_argmin = argmin(a) + 1  # +1するのは問題の数列が1-indexedだから
    ans = ''
    if abs(a_max) >= abs(a_min):
        ans += '{}\n'.format(2 * N - 1)  # 2N-1回の操作でソートされた数列になる
        for i in range(N):
            ans += '{} {}\n'.format(a_argmax, i + 1)  # 各数列に最大値を加算
        for i in range(1, N):
            ans += '{} {}\n'.format(i, i + 1)  # 累積和を取る
    else:
        ans += '{}\n'.format(2 * N - 1)
        for i in range(N):
            ans += '{} {}\n'.format(a_argmin, i + 1)  # 各数列に最小値を加算
        for i in range(N, 1, -1):
            ans += '{} {}\n'.format(i, i - 1)  # 累積和を取る
    ans=ans[:-1] #最後に改行が入ってしまうので、除く
    return ans
  
N = int(input())
A = [int(i) for i in input().split()]
print(d_non_decreasing(N, A))

Measured memory_bytes: 12448
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void){
    // Your code here!	int n,ans=0;
    int n,ans=0;
	cin>>n;
	string s=to_string(n);
	for(int i=0;i<s.size();i++){
		ans=ans+int(s[i]-'0');
		
	}
	
	if(n%ans==0){
		cout<<"Yes"<<endl;
	}
	
	else if(n%ans!=0){
		cout<<"No"<<endl;
	}

}


Measured memory_bytes: 256