akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
  
int F[105][105];
int xg,yg,w,h;
  
  
void DFS(int Y,int X,int c){
  if(F[Y][X] != c){
    return;
  }
  
  F[Y][X] = -1;
  DFS(Y+1,X  ,c);
  DFS(Y-1  ,X,c);
  DFS(Y,X+1  ,c);
  DFS(Y  ,X-1,c);
}
  
  
int main(){
  int xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;
for(int i=0; i<105; i++){
      for(int j=0; j<105; j++){
        F[i][j] = 10;
      }
    }
      
    cin >> xs >> ys >> xg >> yg >> n;
  
  
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;

      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }
  if(F[xs][ys] == 10){
cout << "NG" << endl;
continue;
}
  DFS(xs,ys,F[xs][ys]);
  
  if(F[xg][yg] == -1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3080
n, d = map(int, input().split())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
for i in range(n):
    x[i],y[i] = map(int, input().split())
cnt = 0
for i in range(n):
    dis = x[i]*x[i] + y[i]*y[i]
    if(dis<=d*d):
        cnt+=1
print(cnt)

Measured memory_bytes: 24764
from itertools import accumulate

n, k = map(int, input().split())
books = [[] for _ in range(10)]

while n:
    c, g = map(int, input().split())
    books[g - 1].append(c)
    n -= 1

books_acc = [[0] + list(accumulate(c + i * 2 for i, c in enumerate(sorted(q, reverse=True)))) for q in books]


def memoize(f):
    memo = [[-1] * (k + 1) for _ in range(10)]

    def main(x, y):
        if x > 9:
            return 0
        result = memo[x][y]
        if result < 0:
            result = memo[x][y] = f(x, y)
        return result

    return main


@memoize
def combi(g, remain):
    book_acc = list(books_acc[g])
    salable = min(remain + 1, len(book_acc))
    return max([book_acc[i] + combi(g + 1, remain - i) for i in range(salable)], default=0)


print(combi(0, k))

Measured memory_bytes: 8264
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

#define ll long long

int main(){
    int A, B, max = -200;
    cin >> A >> B;
    if(A+B>max)max = A+B;
    if(A-B>max)max = A-B;
    if(A*B>max)max = A*B;
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
int N,D1,D2,N_,b1,b2,i,j;
main()
{
	std::cin >> N >> D1 >> D2,N_ = N << 1,N *= N;
	while (! (D1 & 3))
		D1 >>= 2,++ b1;
	while (! (D2 & 3))
		D2 >>= 2,++ b2;
	for (i = 0;i < N_;++ i)
		for (j = 0;j < N_;++ j)
			if ((D1 & 1 ? (i >> b1 & 1) == (j >> b1 & 1) : ! (i >> b1 & 1)) && (D2 & 1 ? (i >> b2 & 1) == (j >> b2 & 1) : ! (i >> b2 & 1)))
			{
				std::cout << i << ' ' << j << '\n';
				if (! -- N)
					return 0;
			}
}

Measured memory_bytes: 896
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, d, ans = 0;
    cin >> n >> d;
    for (ll i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        ans += d * d >= x * x + y * y;
    }
    cout << ans;
}

Measured memory_bytes: 3656
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
#define atoi hoge

int hoge(char c) {
    return c - '0';
}
int main()
{
    string s; cin >> s;
    reverse(s.begin(), s.end());
    vector<vector<int>> dp(s.size()+1, vector<int>(2));
    for(int i=0;i < int(s.size()); i++) {
        dp[i+1][0] = min(dp[i][0]+atoi(s[i]), dp[i][1]+atoi(s[i])+1);
        if (i!=0) {
            dp[i+1][1] = min(dp[i][0] + 10 - atoi(s[i]), dp[i][1]+10-(atoi(s[i])+1));
        }else {
            dp[i+1][1] = dp[i][0] + 10 - atoi(s[i]);
        }
    }
    cout << min(dp[s.size()][0], dp[s.size()][1]+1) << "\n";
            
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 55940
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int a;
        int b;

        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();

        int ans = 6 - a - b;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
S =input()
S1 = int(S[:2])
S2 = int(S[2:])
if(S1 == 0):
    if(S2 > 0 and S2 <= 12):
        print("YYMM")
    else:
        print("NA")
elif(S1 > 12):
    if(S2 > 0 and S2 <= 12):
        print("YYMM")
    else:
        print("NA")
else:
    if(S2 > 0 and S2 <= 12):
        print("AMBIGUOUS")
    else:
        print("MMYY")
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int d, sz;
vector<int> dig;
ll mod = 1000000007;

ll dp[10002][101][2];

ll q(int i, int m, int fl) {
    if(i == sz) {
        return (m == 0);
    }
    
    if(dp[i][m][fl] != -1) return dp[i][m][fl];
    
    int lim;
    
    if(fl) lim = 9;
    
    else lim = dig[i];
    
    ll rem = 0;
    
    for(int j = 0; j <= lim; j++) {
        int mm = (m + j + d) % d;
        int ff = fl;
        if(j < dig[i]) ff = 1;
        rem = (rem + q(i + 1, mm, ff) + mod) % mod;
    }
    
    return dp[i][m][fl] = (rem + mod) % mod;
}
int main(){
    string k;
    cin>>k;
    cin>>d;
    for(int i = 0; i < k.length(); i++) {
        dig.push_back(k[i] - '0');
    }
    sz = dig.size();
    for(int i = 0; i < 10002; i++) {
        for(int j = 0; j < 101; j++) {
            dp[i][j][0] = dp[i][j][1] = -1;
        }
    }
  
    ll ans = (q(0, 0, 0) + mod - 1) % mod;
    cout<<ans<<endl;
    
  return 0;
    
}


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

int main(void){
    int n;
    double d;
    cin >> n >> d;
    int cnt = 0;
    double x, y;
    rep(i, n){
        cin >> x >> y;
        if(d >= abs(sqrt(x * x + y * y))) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3776
// Problem : E - This Message Will Self-Destruct in 5s
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n,x;
mi m1,m2;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x;
        m1[i+x]++;
        m2[i-x]++;
    }
    int ans = 0;
    for(auto i:m1){
        if(m2.find(i.fi) != m2.end()) ans += m1[i.fi]*m2[i.fi];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 26656
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){
  string str;
  cin >> str;
  for(int i = 0; i < str.size(); i++){
  bool isn = false;
    switch(str[i]){
      case '1':
        break;
      case '2':
        cout << 'k';
        break;
      case '3':
        cout << 's';
        break;
      case '4':
        cout << 't';
        break;
      case '5':
        cout << 'n';
        break;
      case '6':
        cout << 'h';
        break;
      case '7':
        cout << 'm';
        break;
      case '8':
        cout << 'y';
        break;
      case '9':
        cout << 'r';
        break;
      case '0':
        if(str[i+1] != 'U')cout << 'w';
        else{
          isn = true;
        }
        break;
    }
    i++;
    if(isn){
      cout << "nn";
      continue;
    }
    switch(str[i]){
      case 'T':
        cout << 'a';
        break;
      case 'L':
        cout << 'i';
        break;  
      case 'U':
        cout << 'u';
        break;  
      case 'R':
        cout << 'e';
        break;  
      case 'D':
        cout << 'o';
        break;  
    }
  }
    cout << endl;
  return 0;
}




Measured memory_bytes: 3220
#include <stdio.h>

int selectionSort(int A[], int N) {
	int i, j, t, minj;
	int sw = 0;

	for ( i = 0; i < N-1; i++) {
		minj = i;
		for( j = i; j < N; j++) {
			if ( A[j] < A[minj] ) {
				minj = j;
			}
		}
		t = A[i];
		A[i] = A[minj];
		A[minj]	= t;
		if ( i != minj) {
			sw++;
		}
	}
	
	return sw;
}

int main()
{
	int A[100], N, i, sw;

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

	sw = selectionSort(A, N);

	for ( i = 0; i< N; i++) {
		if ( i > 0) {
			printf (" ");
		}
		printf("%d", A[i]);
	}
	printf("\n");
	printf("%d\n", sw);

	return 0;
}

Measured memory_bytes: 604
N,M=map(int,input().split())
Y=[list(map(int,input().split())) for i in range(M)]
Y.sort(key=lambda x:x[1])
K=1
x=Y[0][1]
for a,b in Y[1:]:
    if a+1>x:
        x=b
        K+=1
print(K)


Measured memory_bytes: 65240
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<long long>;
using vvi=vector<vector<long long>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000009;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

int gcd(int a,int b){
  while(true){
  if(b==0)return a;
  if(a>b)swap(a,b);
  b=b%a;
  }
}
int main(){
  int n;cin>>n;
  int ans=1;
  vi v(n),l(n),r(n);
  rep(i,n)cin>>v[i];
  l[0]=v[0];
  for(int i=1;i<n;i++){
    l[i]=gcd(v[i],l[i-1]);
  }
  r[n-1]=v[n-1];
  for(int i=n-2;i>=0;i--){
    r[i]=gcd(v[i],r[i+1]);
  }
  ans=max(r[1],l[n-2]);
  for(int i=1;i<n-1;i++){
    chmax(ans,gcd(l[i-1],r[i+1]));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;
    int i;
    int ans = 0;

    cin >> n;
    vector<int> b(n), a(n);

    for (i = 0; i < n - 1; i++)
    {
        cin >> b[i];
    }

    a[0] = b[0];

    for (i = 1; i < n; i++)
    {
        a[i] = b[i - 1];

        a[i - 1] = min(a[i - 1], b[i - 1]);
    }

    for (i = 0; i < n; i++)
    {
        ans += a[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int X[110],Y[110];

int main(){
  int W,H,N,x,y,a,ansX=0,ansY=0;
  cin>>W>>H>>N;

  for(int i=0;i<N;i++){
    cin>>x>>y>>a;
    if(a==1){
      for(int i=0;i<x;i++) X[i]=1;
    }else if(a==2){
      for(int i=x;i<W;i++) X[i]=1;
    }else if(a==3){
      for(int i=0;i<y;i++) Y[i]=1;
    }else{
      for(int i=y;i<H;i++) Y[i]=1;
    }
  }

  for(int i=0;i<W;i++) if(X[i]==0) ansX++;
  for(int i=0;i<H;i++) if(Y[i]==0) ansY++;
  cout<<ansX*ansY<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    int n;
    ll mod = 1e9+7;
    string s;
    cin >> n >> s;

    map<char, int> cnt;
    int slen = s.length();
    rep(i, slen){
        cnt[s[i]]++;
    }

    ll res = 1;
    for(auto const& e : cnt){
        res *= (e.second + 1);
        res %= mod;
    }
    cout << res-1 << endl;

    return 0;
}


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

int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K; for (ll i = 0; i < N; ++i) {ll _; cin >> _;}
	ll res{1};
	for (ll i = K; i < N; i+=(K-1)) ++res;
	std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const int MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int cnt[1009];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		int tmp = i;
		for (int j = 2; tmp > 1; j++) {
			while (tmp % j == 0) {
				cnt[j]++;
				tmp /= j;
			}
		}
	}
	long long ans = 1;
	for (int i = 1; i <= n; i++) {
		ans = ans * (cnt[i] + 1) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import scipy.sparse
H,W = (int(x) for x in input().split())
lines = [input() for i in range(H)]
lil = scipy.sparse.lil_matrix((H*W, H*W), dtype = int)
for i in range(H):
    for j in range(W):
        if i == j == 0: continue
        elif i == 0 and j > 0:
            if lines[0][j] == lines[0][j-1] == ".":
                lil[i*W+j, i*W+j-1] = 1
                lil[i*W+j-1, i*W+j] = 1
        elif i > 0 and j == 0:
            if lines[i][0] == lines[i-1][0] == ".":
                lil[i*W+j, (i-1)*W+j] = 1
                lil[(i-1)*W+j, i*W+j] = 1
        else:
            if lines[i][j] == lines[i][j-1] == ".":
                lil[i*W+j, i*W+j-1] = 1
                lil[i*W+j-1, i*W+j] = 1
            if lines[i][j] == lines[i-1][j] == ".":
                lil[i*W+j, (i-1)*W+j] = 1
                lil[(i-1)*W+j, i*W+j] = 1
lil2 = scipy.sparse.csgraph.dijkstra(lil, directed = False, indices=[0,H*W-1]).astype(int)
a = lil2[0][H*W-1]
if a <= 0:
    print("-1")
else:
    b = "".join(lines).count(".")
    print(b-a-1)

Measured memory_bytes: 17416
package main

import (
        "fmt"
        "strconv"
        "strings"
)

var set map[string]struct{}

func main() {
        var N int
        var S string
        fmt.Scanf("%d\n%s", &N, &S)
        ans := 0
        for i := 0; i < 10; i++ {
                ii := strings.Index(S, strconv.Itoa(i))
                if ii != -1 {
                        for j := 0; j < 10; j++ {
                                ij := strings.Index(S[ii+1:], strconv.Itoa(j))
                                if ij != -1 {
                                        for k := 0; k < 10; k++ {
                                                ik := strings.Index(S[ii+ij+2:], strconv.Itoa(k))
                                                if ik != -1 {
                                                        ans += 1
                                                }
                                        }
                                }
                        }
                }
        }
        fmt.Println(ans)

}

Measured memory_bytes: 896
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int l = sc.nextInt();
        String s[] = new String[n];
        for(int i = 0; i < n; i++){
        	s[i] = sc.next();
        }
        Arrays.sort(s);
        for(int i = 0; i < n; i++){
        	System.out.print(s[i]);
        }
        System.out.println();
    }
}

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

int main(){
  
  int n,k;cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  
  if(k>=n-1){
    cout<<abs(arr[0]-arr[n-1])<<"\n";
    return 0;
  }
  
int dp[n];
  memset(dp,-1,sizeof(dp));
  
  dp[0]=0;
  for(int i=1;i<=k;i++){
   dp[i] = abs( arr[0]-arr[i] );
  }
  
  for(int i=k+1;i<n;i++){
     int ans=INT_MAX; 
    for(int j=1;j<=k;j++){
       ans= min(ans , abs(arr[i]-arr[i-j]) + dp[i-j] );
      } 
    
    dp[i] = ans;
  }
  
  cout<<dp[n-1]<<"\n";
  
}

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

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    string r = s;
    reverse(r.begin(), r.end());
    string t = s + r;
    if (k == 1) {
        string ans(n, 'z');
        for (int i = 0; i <= n; ++i) {
            ans = min(ans, t.substr(i, n));
        }
        cout << ans << "\n";
        return 0;
    }
    const char kA = *min_element(s.begin(), s.end());
    int best = -1;
    vector<string> cd;
    for (int i = 0; i <= n; ++i) {
        int j = i + n - 1, cnt = 0;
        while (j >= i && t[j] == kA) --j, ++cnt;
        if (cnt > best) {
            best = cnt;
            cd = {t.substr(i, n)};
        } else if (cnt == best) {
            cd.push_back(t.substr(i, n));
        }
    }
    assert(best >= 1);
    string ans(n, 'z');
    for (auto s : cd) {
        int suf = best;
        for (int it = 0; it < k - 1; ++it) {
            if (suf * 2 >= n) {
                cout << string(n, kA) << "\n";
                return 0;
            }
            if (it + 1 == k - 1) {
                string r = s;
                reverse(r.begin(), r.end());
                ans = min(ans, string(suf, kA) + r.substr(0, n - suf));
            } else {
                s = s.substr(suf) + string(suf, kA);
                suf <<= 1;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 11904
def main():
    import itertools
    import re

    n = int(input())
    s = input()

    cnt = 0
    for key in itertools.product('0123456789', repeat=3):
        key1, key2, key3 = map(str, key)
        if key1 in s:
            key1_idx = s.find(key1)
            if key2 in s[key1_idx+1:]:
                key2_idx = key1_idx + s[key1_idx+1:].find(key2) + 1
                if key3 in s[key2_idx+1:]:
                    cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  if(n%k == 0) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int e;
	while (scanf("%d", &e), e) {
		int m = 10000000;
		for (int y = 0; y <= 1000; y++) {
			for (int z = 0; z <= 1000; z++) {
				int x=e + y - y * y + z - z * z * z;
					if(x>=0&&e>=y*y+z*z*z) m = min(x,m);
			}
		}
		cout<<m<<endl;
	}
}




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

int main()
{
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

 	int n,y ;

	cin>>n>>y;
	if(y%2 != 0 ) cout<<"No\n";
	else{
		
		if(y/2 - n >=0 && y/2 - n <= n) cout<<"Yes\n";
		else cout<<"No\n";
		
	}  

  return 0;
}


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

using namespace std;

#define all(a) (a).begin(),(a).end()

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;*/
    
    int n,m;cin>>n>>m;
    vector<vector<char>> g(n+2,vector<char>(m+2,'#'));
    vector<vector<int>> row(n+2),col(m+2);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>g[i][j];
        }
    }
    for(int i=0;i<=n+1;i++){
        for(int j=0;j<=m+1;j++){
            if(g[i][j]=='#'){
                row[i].push_back(j);
                col[j].push_back(i);
            }
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(g[i][j]=='.'){
                int num=0;
                auto r1=lower_bound(all(row[i]),j)-row[i].begin();
                num+=row[i][r1]-row[i][r1-1]-1;
                auto r2=lower_bound(all(col[j]),i)-col[j].begin();
                num+=col[j][r2]-col[j][r2-1]-2;
                ans=max(ans,num);
            }
        }
    }
    cout<<ans;
    
    /*#ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
    return 0;
}

Measured memory_bytes: 38400
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int a, b;
    scan(a, b);
    auto ans = a * (a - 1) / 2 + b * (b - 1) / 2;
    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 256
c1 = list(int(i) for i in input().split())
c2 = list(int(i) for i in input().split())
c3 = list(int(i) for i in input().split())

flag1 = False
flag2 = False

for i in range(101):
    if c1[0]+i == c2[0] and c1[1]+i == c2[1] and c1[2]+i == c2[2]:
        flag1=True
    elif c1[0]-i == c2[0] and c1[1]-i == c2[1] and c1[2]-i == c2[2]:
        flag1=True
        
for i in range(101):
    if flag1 == True:
        if c1[0]+i == c3[0] and c1[1]+i == c3[1] and c1[2]+i == c3[2]:
            flag2=True
        elif c1[0]-i == c3[0] and c1[1]-i == c3[1] and c1[2]-i == c3[2]:
            flag2=True

if flag2 == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N = int(input())
N_List = list(map(int,input().split()))[-1::-1] 
for i in range(1,N):
    if N_List[i-1] < N_List[i]:
        if N_List[i-1] + 1 == N_List[i]:
            N_List[i] -= 1
        else:
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 20488
/* code by AbhiTaker
         ____
        /    \
       /  __  \              _______      __       _   _    _____    _____
      /  /  \  \            |__   __|    /  \     | | / /  |  ___|  |  _  \
     /  /____\  \     ___      | |      / /\ \    | |/ /   | |__    | |_)  )
    /  /______\  \   |___|     | |     / /__\ \   |   /    |  __|   |    _/
   /  /        \  \            | |    / /----\ \  | |\ \   | |___   | |\ \
  /__/          \__\           |_|   /_/      \_\ |_| \_\  |_____|  |_| \_\
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 1000016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000
pair<ll, ll>  a[N],b[N];
unordered_set<ll> p[N], p2[N],trk;

int main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
   ll n,i,j;
   cin>>n;
   for(i=0;i<n; i++)
    cin>>a[i].f>>a[i].s;
   for(i=0;i<n; i++)
    cin>>b[i].f>>b[i].s;

    for(i=0; i<n; i++)
    {
        for(j=0 ; j<n; j++)
        {
            if(b[j].f > a[i].f && b[j].s > a[i].s)
            {
                trk.insert(i);
                p[i].insert(j);
                p2[j].insert(i);
            }
        }
    }
    ll cnt = 0;
    while(!trk.empty())
    {
        ll sz = inf,elem = 0;
        vector<ll> rem;

        for(auto i: trk)
        {
            if(p[i].empty())
            {
                rem.push_back(i);
                continue;
            }
            if(p[i].size() < sz)
            {
                sz = p[i].size();
                elem = i;
            }
        }
        for(auto i: rem)
            trk.erase(i);
        trk.erase(elem);
        if(sz==inf)
            break;
        sz = inf;
        ll elem2 = 0;
        for(auto i: p[elem])
        {
            if(p2[i].size() < sz)
            {
                sz = p2[i].size();
                elem2  = i;
            }
        }
        cnt++;

        for(auto i: p[elem])
            p2[i].erase(elem);
        for(auto i: p2[elem2])
            p[i].erase(elem2);
    }

    cout<<cnt<<"\n";

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string a, b;
    cin >> a >> b;
    int na = a.size(), nb = b.size();
    vector<vector<int>> lcs(na+1, vector<int> (nb+1));
    for(int i = 0; i <= na; i++) {
        for(int j = 0; j <= nb; j++) {
            if (i == 0 || j == 0) {
                lcs[i][j] = 0;
            } else {
                lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
                if (a[i-1] == b[j-1]) {
                    lcs[i][j] = max(lcs[i][j], lcs[i-1][j-1] + 1);
                }
            }
        }
    }

    string ans = "";
    int x = na, y = nb;
    while(x && y) {
        if (lcs[x][y] == lcs[x-1][y]) {
            x--;
        } else if (lcs[x][y] == lcs[x][y-1]) {
            y--;
        } else {
            ans += a[x-1];
            x--, y--;
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}


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

//SET PRECIOSION   cout << fixed ;  cout << setprecision(n) << ans << endl;
#define ll long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector <ll> v,w;
ll x,y,z,a,b,c,sum,ans,total,t,cnt,n,m,k,p,kase;
ll dp[101][100009];
string s1,s2;
map<ll,ll> mp;
set<ll> s;
map<ll,ll> :: iterator itr1, ptr1;
set<ll> :: iterator itr, ptr;
ll coinChange(ll i, ll amount)
{
    if(amount==0)
        return 0;
    if(i>=n)
    {
            return INT_MAX;
    }
    if(dp[i][amount]!=-1)
        return dp[i][amount];
    ll ret1 = INT_MAX, ret2 = INT_MAX;
    if(amount-v[i]>=0)
        ret1 = coinChange(i+1, amount-v[i])+w[i];
    ret2 = coinChange(i+1, amount);
    dp[i][amount]= min(ret1,ret2);
    return dp[i][amount];
}
int main()
{
	FAST;
	cin>>n>>k;
	memset(dp,-1,sizeof(dp));
	v.resize(n+1);
	w.resize(n+1);
	for(int i=0; i<n; i++)
    {
           cin>>w[i]>>v[i];
           sum+=v[i];
    }
    while(sum--)
    {

        if(coinChange(0,sum+1)<=k)
        {
            cout<<sum+1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
	//clear vectors and maps you idiot
	// check array size dumb
	// use long long instead of int too
	return 0;
}


Measured memory_bytes: 79232
object Main extends App {
  var a = readLine.split(" ").map(_.toLong)
  var b = readLine.split(" ").map(_.toLong).sorted
  var sum = 0L
  for(i <- 0 until a(0).toInt - 1 if(a(1) >= b(i))) {
      a(1) -= b(i)
      sum = sum + 1
  }
    if(a(1) == b(a(0).toInt - 1)) {
      sum = sum + 1
    }
  print(sum)
}

Measured memory_bytes: 25416
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #pragma optimize("TKACHENKO-GORYACHENKO")
#define x first
#define y second
#pragma GCC optimize("O3")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
// #pragma comment(linker, "/stack:2000000000")
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 1e6;
const ll inf = 1e9;

ll n, m, k, t;

vector <ll> V[maxn];

ll H[maxn];

ll CNT[2];

ll ANS[maxn];

vector <ll> A[3];

void dfs(ll v, ll p) {
    ll q;
    if (v != p) {
        H[v] = H[p] + 1;
    }
    CNT[H[v] % 2]++;
    for (q = 0; q < V[v].size(); q++) {
        ll v1 = V[v][q];
        if (v1 == p) {
            continue;
        }
        dfs(v1, v);
    }
}

int main() {
    ll q, w, e, a, b, c, d;
    string s;
    cin >> n;
    for (q = 0; q < n - 1; q++) {
        cin >> a >> b;
        a--; b--;
        V[a].pb(b); V[b].pb(a);
    }
    dfs(0, 0);
    for (q = 1; q <= n; q++) {
        A[q % 3].pb(q);
    }
    for (q = 0; q < 2; q++) {
        if (A[0].size() >= CNT[q]) {
            for (w = 0; w < n; w++) {
                if (H[w] % 2 == q) {
                    ANS[w] = A[0].back();
                    A[0].pop_back();
                }
                else {
                    for (e = 2; e >= 0; e--) {
                        if (!A[e].empty()) {
                            ANS[w] = A[e].back();
                            A[e].pop_back();
                            break;
                        }
                    }
                }
            }
            for (w = 0; w < n; w++) {
                cout << ANS[w] << " ";
            }
            return 0;
        }   
    }
    for (q = 0; q < n; q++) {
        // if (H[q] % 2 == 1) {
        ll ost = H[q] % 2 + 1;
        // cout << ost << " " << q << endl;
        if (A[ost].empty()) {
            if (A[0].empty()) {
                cout << -1;
                return -1;
            }
            // cout << "HERE " << A[0].back() << endl;
            ANS[q] = A[0].back();
            A[0].pop_back();
            continue;
        }
        ANS[q] = A[ost].back();
        A[ost].pop_back();
        // }
    }
    for (q = 0; q < n; q++) {
        cout << ANS[q] << " ";
    }
    return 0;
}


Measured memory_bytes: 42984
import numpy as np
 
Tmp = []
Tmp = input().rstrip().split(' ')
 
nN = int(Tmp[0])
nM = int(Tmp[1])
nC = int(Tmp[2])
nAns = 0
ListA = [0 for i in range(nM)]
ListB = [0 for i in range(nM)]
Tmp = input().rstrip().split(' ')
for i in range(nM):
  ListB[i] = int(Tmp[i])
nAns = 0
 
for i in range(nN):
  Tmp = input().rstrip().split(' ')
  for j in range(nM):
    ListA[j] = int(Tmp[j])

    
#  nTmp = np.dot(ListA, ListB.T)
  nTmp = 0
  for j in range(nM):
    nTmp += ListA[j] * ListB[j]
  nTmp += nC
  if nTmp > 0:
    nAns += 1

print(nAns)
 

Measured memory_bytes: 12400
#include<stdio.h>
int main(){
  int n,T,t[200001],i,sum=0;
  scanf("%d%d",&n,&T);
  for(i=0; i<n; i++){
    scanf("%d",&t[i]);
  }
  for(i=0; i<n-1; i++){
    if(t[i+1]-t[i]>=T){
      sum+=T;
    }
    else{
      sum+=(t[i+1]-t[i]);
    }
  }
  sum=sum+T;
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 896
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str;
		try{
			while((str=br.readLine())!=null){
				char[] ch=str.toCharArray();
				for(int i=0;i<ch.length;i++){
					if('a'<=ch[i]&&'z'>=ch[i]){
						ch[i]-=32;
					}
				}
				System.out.println(ch);
			}
		}catch(Exception e){
		}
	}
}

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

double fukuri( int y, int r ){
  double ans = 1;
  for ( int i = 0; i < y; i++ )  ans *= 1 + r/100.0;
  return ans;
}

double tanri( int y, int r ){
  return 1 + y * (r/100.0);
}

main(){
  int n, y, b, r, ans, t;
  double maxv , var;

  while(1){
    cin >> n;
    if ( n == 0 ) break;
    cin >> y;
    maxv = -1;

    for ( int i= 0; i < n; i++ ){
      cin >> b >> r >> t;

      if ( t == 2 ) var = fukuri(y, r);
      else if ( t == 1)  var = tanri(y, r);

      if ( maxv < var ){
	maxv = var;
	ans = b;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",c);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}		
int a[114514],b[114514];
string ss[114514];
signed main(){
	ic(n) ic(k)
	rep(0,i,1001){
		if(i*2/25==n&&i/10==k){
			c(i)
			return 0;
		}
	}
	c(-1)	
}	

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename T>
struct Maybe {
   T x;
   bool valid;
   Maybe() : valid(false) {}
   Maybe(T x_) : x(x_), valid(true) {}
   operator T() const {
      assert( valid );
      return x;
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      std::string ss, ts; scan(ss, ts);
      for(Int i = (Int)ss.size()-(Int)ts.size(); i >= 0; --i) {
         bool flag = true;
         for(Int k = 0; k < (Int)ts.size(); ++k) {
            if( not ( ss[i+k] == '?' or ss[i+k] == ts[k] ) ) {
               flag = false;
            }
         }
         if( flag ) {
            for(Int k = 0; k < (Int)ts.size(); ++k) {
               ss[i+k] = ts[k];
            }
            for(char& c : ss) {
               if( c == '?' ) c = 'a';
            }
            printf("%s\n", ss.c_str());
            return;
         }
      }
      puts("UNRESTORABLE");
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main(void){
  int w,i;
  string s;
  
  cin >> s >> w;
  i=0;
  while (i<s.size()){
    cout << s[i];
    i+=w;
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
dice_arr = gets.split.map(&:to_i)
direction = gets

direction.each_char do |c|
  case c
  when "N"
    dice_arr = 
      [
        dice_arr[1],
        dice_arr[5],
        dice_arr[2],
        dice_arr[3],
        dice_arr[0],
        dice_arr[4]
      ]

  when "S"
    dice_arr = 
      [
        dice_arr[4],
        dice_arr[0],
        dice_arr[2],
        dice_arr[3],
        dice_arr[5],
        dice_arr[1]
      ]
  
  when "E"
    dice_arr = 
      [
        dice_arr[3],
        dice_arr[1],
        dice_arr[0],
        dice_arr[5],
        dice_arr[4],
        dice_arr[2]
      ]
  
  when "W"
    dice_arr = 
      [
        dice_arr[2],
        dice_arr[1],
        dice_arr[5],
        dice_arr[0],
        dice_arr[4],
        dice_arr[3]
      ]
  end
end

puts dice_arr[0]

Measured memory_bytes: 6104
n = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = sum(b)
for i in range(n-1):
	if a[i] + 1 == a[i+1]:
		ans += c[a[i]-1]

print(ans)



Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		int a[];
		int index;
		int count;
		int pass;

		n = sc.nextInt();
		m = sc.nextInt();
		while (n + m != 0) {
			index = -1;
			count = 0;
			pass = 0;
			a = new int[n];
			while (count < n - 1) {
				index++;
				index %= n;
				if (a[index] == 0) {
					pass++;
				}
				if (pass == m) {
					a[index] = 1;
					pass = 0;
					count++;
				}
			}
			for (int i = 0; i < n; i++) {
				if (a[i] == 0) {
					System.out.println(i + 1);
				}
			}
			n = sc.nextInt();
			m = sc.nextInt();
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;  
return;  
}


int main(void)
{
int a,i,b,j;
  scanf("%d",&a);
float num[a];
  for(i=0;i<a;++i)
  {
  scanf("%f",&num[i]);
  }
  b=a;
  for(i=1;i<a;++i)
  {
    for(j=1;j<b;++j)
    {
    if(num[j-1]>num[j]) swap(&num[j-1],&num[j]);
    } 
   b--; 
  } 
float ans[a];
  ans[1]=(num[0]+num[1])/2;
  
  for(i=1;i<a-1;++i)
  {
  ans[i+1]=(ans[i]+num[i+1])/2;
  }
  
  printf("%f",ans[a-1]);

  
return 0;
}

Measured memory_bytes: 128
fee n
  | n > 30 = 160 * (n-30) + 140 * 10 + 125 * 10 + 1150
  | n > 20 = 140 * (n-20) + 125 * 10 + 1150
  | n > 10 = 125 * (n-10) + 1150
  | otherwise = 1150

ans n =
  let f = fee n
  in
    4280 - f

main = do
  c <- getContents
  let i = takeWhile (/= -1) $ map read $ lines c :: [Int]
      o = map ans i
  mapM_ print o

Measured memory_bytes: 4060
#include <stdio.h>

int main(void) {    

int a ,b ,c ,d;    

scanf("%d %d %d\n" ,&a ,&b ,&c);    

if(a>b){      

d = b;   

b = a;   

a = d;     

}    

if(a>c){      

d = c;   

c = a;   

a = d;     

}    

if(b>c){      

d = c;   

c = b;   

b = d;     

}    

printf("%d %d %d\n" ,a ,b ,c);    

return 0;  

}
 

Measured memory_bytes: 600
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
int arsort(const void *a,const void *b){
    if(*(int*)a>*(int*)b )return 1;
    return -1;
}
typedef struct{
    long long cards;
    long long number;
} set;
int stcompare(const void *a,const void *b){
    set x=*(set *)a;
    set y=*(set *)b;
    long long p=x.number,q=y.number;
    if(p>q)return -1;
    return 1;
}
int main()
{   int n,m;
    scanf("%d%d",&n,&m);
    long long a[n];
    set arr[m];
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    if(n>1){
    qsort(a,n,sizeof(long long),arsort);
    }
    for(int i=0;i<m;i++){
        scanf("%lld%lld",&arr[i].cards,&arr[i].number);
    }
    if(m>1){
    qsort(arr,m,sizeof(set),stcompare);
    }
    int pa=0,pc=0;
    while(1){
        if(arr[pc].cards==0){
            pc++;
        }
        if(pc>=m)break;
        if(a[pa]<=arr[pc].number){
                a[pa]=arr[pc].number;
                arr[pc].cards--;
                pa++;
                if(pa>=n){
            break;
        }
        }else{
            break;
        }
        
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=a[i];
    }
    printf("%lld",ans);
    return 0;
}


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

int main() {
 int seged=0;
 string S="ASSA";
 cin >> S;
 for(int i=0;i<S.length()-1;i++){
   for(int j=i+1;j<S.length();j++){
     if(S[i]==S[j]){
       seged+=1;
     }
   }
 }
 if(seged==2){
   cout << "Yes";
 }else{
   cout << "No";
 }
 	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int array[3],i,j,a;
	for(i=0;i<3;i++){
		scanf("%d",&array[i]);
	}for(i=0;i<2;i++){
		for(j=2;j>i;j--){
			if(array[j-1]>array[j]){
				a=array[j-1];
				array[j-1]=array[j];
				array[j]=a;
			}
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
	return 0;
}

Measured memory_bytes: 2728
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<int,int> a, const pair<int,int> b) {
    return a.second < b.second;
}

ll gcd(ll a,ll b){
  if(a%b == 0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}

const int MAX = 510000;
const int MOD = 1000000007;

int main(){

    int N;

    cin >>N;

    vector<pair<int,int>> list;

    for(int i = 0;i < N;i++){
        int Ai;
        cin >>Ai;
        list.push_back(make_pair(i+1,Ai));
    }

    sort(list.begin(),list.end(),comp);

    for(int i = 0;i < list.size();i++){
        cout <<list[i].first<<" ";
    }
    cout <<endl;
    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;

*/

Measured memory_bytes: 1780
import java.util.*;
public class Main {
    public static void main (String args[])
    {
        Scanner cin = new Scanner(System.in);
        int a = cin.nextInt(), b = cin.nextInt();
        if ((a*b) % 2 == 0) {
            System.out.print("Even");
        }
        else {
            System.out.print("Odd");
        }
    }
}

Measured memory_bytes: 21716
n=int(input())
T,X,Y=0,0,0

a='Yes'
for i in range(n):
    t,x,y=map(int,input().split())
    if abs(x-X)+abs(y-Y)>t-T or t%2!=(x+y)%2:
        a='No'
        break
    T,X,Y=t,x,y
print('{}'.format(a))

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma comment(linker, "/STACK:2000000")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'
using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 3e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
void printCase(int cs){
  cout << "Case #" << cs<<": ";
}
vector<ll>getDivs(ll x){
  vector<ll> ret;
  for(ll i = 1; i * i <= x; i++){
    if(x%i==0){
      ret.push_back(i);
      if(i*i!=x)ret.push_back(x/i);
    }
  }
  sort(ret.rbegin(),ret.rend());
  return ret;
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
  ll n;
  cin>> n;
  ll ans = 0;



  auto x = getDivs(n);
  x.pop_back();
  for(auto i : x){
    ll tmp = n;
    while(tmp%i==0)tmp/=i;
    if(tmp%i==1){
      ans++;
    }
  }
  auto y = getDivs(n-1);
  y.pop_back();

  ans+=y.size();

  cout<<ans<<'\n';


  return 0;
}


Measured memory_bytes: 384