akhauriyash/Code-Regression huggingface dataset:
/*在线求区间内不同的数的个数：从头到尾添加到线段树（不是权值线段树，是存值的线段树）中
如果此数之前出现过就先减去，接着再加，最后在区间(l,r)中找到root[r]这个历史版本*/
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
#define dir(a,b) (a>>b)
const int Max=5e5 + 10;
int root[Max],tot,val[Max];
struct node
{
    int lef,rig,sum;
}msegtr[Max*40];
map<int,int> mp;
void Init()
{
    tot=0;
    msegtr[0].lef=msegtr[0].rig=msegtr[0].sum=0;
    root[0]=0;
    mp.clear();
    return;
}
void Create(int sta,int enn,int &x,int y,int pos,int aad)
{
    msegtr[++tot]=msegtr[y];
    msegtr[tot].sum+=aad;
    x=tot;
    if(sta==enn)
        return;
    int mid=dir(sta+enn,1);
    if(mid>=pos)
        Create(sta,mid,msegtr[x].lef,msegtr[y].lef,pos,aad);
    else
    Create(mid+1,enn,msegtr[x].rig,msegtr[y].rig,pos,aad);
    return;
}
int Query(int sta,int enn,int x,int y)//只有左边有界限
{
    if(sta>=y)
        return msegtr[x].sum;
    int mid=dir(sta+enn,1);
    if(mid>=y)
        return Query(sta,mid,msegtr[x].lef,y)+msegtr[msegtr[x].rig].sum;
    else
        return Query(mid+1,enn,msegtr[x].rig,y);
}
signed main()
{
    int n,m,temp;
    int lef,rig;
    int q;
    while(~scanf("%lld%lld",&n, &q))
    {
         Init();
    for(int i=1;i<=n;++i)
    {
        scanf("%lld",&val[i]);
        if(!mp.count(val[i]))//直接加
        {
            Create(1,n,root[i],root[i-1],i,1);//注意是在i这个位置加1，不是权值线段树的val[i]位置加1
        }
        else
        {
            Create(1,n,temp,root[i-1],mp[val[i]],-1);//先在原位置减去1
            Create(1,n,root[i],temp,i,1);
        }
        mp[val[i]]=i;
    }
    for(int i=0;i<q;++i)
    {
        scanf("%lld %lld",&lef,&rig);
        printf("%lld\n",Query(1,n,root[rig],lef));//在rig的历史版本上找(lef,rig)的值
    }
    }
    return 0;
}

Measured memory_bytes: 479248
N, M, X = map(int, input().split())
C = [0]*N
A = [[0 for _ in range(M)] for _ in range(N)]
for i in range(N):
    for j, x in enumerate(map(int, input().split())):
        if j == 0:
            C[i] = x
        else:
            A[i][j-1] = x

ans = 10**5*12+1
for bit_pattern in range(2<<N-1):
    i = 0
    tmp = [0]*M
    cost = 0

    while bit_pattern > 0:
        if bit_pattern & 1:
            for j in range(M):
                tmp[j] += A[i][j]
            cost += C[i]
        bit_pattern >>= 1
        i += 1

    for j in range(M):
        if tmp[j] < X:
            break
        if j == M-1:
            ans = min(ans, cost)
if ans == 10**5*12+1:
    ans = -1
print(ans)

Measured memory_bytes: 68340
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr2(i,s,n) for (int i = (n-1); i>=(int)(s);i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Grid = vector<vector<int>>;
const ll INF = 10011032323450010;
const ld PI = 3.14159265358979323846;



int main() {
     
    int N;
    cin>>N;
    vector<vector<int>> A(N,vector<int>(2));
    rep(i,N){
        cin>>A[i][0];
    }
    A[0][1]=0;
    int count=1;
    rep2(i,1,N){
        if(A[i-1][1]==0){
            
            if(A[i][0]>A[i-1][0]){
                A[i][1]=1;

            }
            else if(A[i][0]<A[i-1][0]){
                A[i][1]=-1;
            }
            else{
                A[i][1]=0;
            }
        }
        else if(A[i-1][1]==1){
            if(A[i][0]>=A[i-1][0]){

                
                A[i][1]=1;
            }
            else{
                count++;
                A[i][1]=0;
                

            }
        }
        else{
            if(A[i][0]<=A[i-1][0]){
                A[i][1]=-1;
            }
            else{
                count++;
                A[i][1]=0;
            }
        }
    }
    cout<<count<<endl;

return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

    vector<vector<ll>> dp(11);

    for(ll i=1;i<10;i++)dp[1].push_back(i);
    for(ll i=2;i<11;i++){
        for(ll j=0;j<dp[i-1].size();j++){
            ll a=dp[i-1][j];
            if(a%10==0){
                dp[i].push_back(a*10);
                dp[i].push_back(a*10+1);
            }
            else if(a%10==9){
                dp[i].push_back(a*10+8);
                dp[i].push_back(a*10+9);
            }
            else{
                dp[i].push_back(a*10+a%10);
                dp[i].push_back(a*10+a%10-1);
                dp[i].push_back(a*10+a%10+1);
            }
        }
    }
    

    vector<long long int> b;

    
    
    for(int i=1;i<11;i++){
        for(int j=0;j<dp[i].size();j++){
            b.push_back(dp[i][j]);
        }
    }
    

    sort(b.begin(),b.end());

    //cout << b.size() << endl;


    int d;

    cin >> d ;

    cout << b[d-1] << endl; 

}

Measured memory_bytes: 6816
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <cmath>

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

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI t(n), a(n);
	rep(i,n) cin >>t[i];
	rep(i,n) cin >>a[i];
	

	if(t.back() != a.front()) {puts("0"); return 0;}
	
	VI kt(n, -1), ck(n , -1);
	kt[0] = t.front(); kt.back()=a.back();
	rep(i,n-1) if(t[i] < t[i+1]) kt[i+1] = t[i+1];
	repr(i,n-1,0) if(a[i] > a[i+1]) kt[i] = a[i];
	
	rep(i,n) if(kt[i]>=0){
		if(kt[i] > a[i] || kt[i] >t[i]) {puts("0"); return 0;}
	}
	
	if(n==1) {puts("1"); return 0;}
	
	//for(auto x :kt) printf("%d, ",x); puts("");
	ll ans  = 1;
	rep(i,n) if(kt[i]==-1){
		(ans *= (ll)min(a[i],t[i])) %=mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>
#define f first
#define s second
#define inf 1e18
#define ll long long
#define mod 1000000007
#define pb emplace_back
#define vll vector<long long>
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) ((long long)(x).size())
#define mll map<long long, long long>
#define pll pair<long long, long long>
using namespace std;

ll n;

void input(){
	cin >> n;
}

void solve(){
	if(n >= 30)cout<<"Yes";
	else cout<<"No";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(20);
	ll t;
	t = 1;
	//cin >> t;
	while(t--){
		input();
		solve();
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3644
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 六 12/15 19:59:59 2018

*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

const int MAXN = 2e5;

char s[MAXN+5];

int main()
{
	while(~scanf("%s", s + 1)){
		LL cnt = 0, ans = 0;
		int len = strlen(s + 1);
		for(int i = 1; i <= len; i++){
			if(s[i] == 'B') cnt++;
			else ans += cnt;
		}
		cout << ans << endl;
	}
    return 0;
}


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    int n;
    cin>>n;
    vi a(1e6+1);
    vector <int> b(n);
    rep(i,n)
    cin>>b[i],a[b[i]]++;
    int ans=0;
    for (auto x:b)
    {
        bool ok=true;
        for (int i=1;i*i<=x;i++)
        {
            if (x%i==0)
            {
                if (a[i]&&i!=x)
                {
                    ok=false;
                    break;
                }
                if (x/i==x)
                {
                    if (a[x]>1)
                    {
                        ok=false;
                        break;
                    }
                }
                else
                {
                    if (a[x/i])
                    {
                        ok=false;
                        break;
                    }
                }
            }
        }
        if (ok)
            ans++;
    }
    cout<<ans;


    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 7924
/*
   逆ポーランド法の式が入力される。
   逆ポーランド法の式を展開して、計算結果を出力。

   演算子は*,+,-の三種類。

   input:
   1 2 + 3 4 - *

   output:
   -3

   スタックに式を入力(push)。演算子が検出されたら、2つの値をpop
   し、スタックに再度入力。
   スタックに最後に残ったものが出力される。
*/

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

int top;
int S[200];

void push(int x)
{
   // topを加算してからその位置へ挿入
   S[++top] = x;
}

int pop() 
{
   top--;
   // topが指していた要素を返す
   return S[top+1];
}


int main()
{
   int top = 0;
   int a,b;
   char s[8];

   while (scanf("%s", s) != EOF) {
      if (s[0] == '+') {
         a = pop();
         b = pop();
         push(a + b);
      } else if (s[0] == '*') {
         a = pop();
         b = pop();
         push(a * b);
      } else if (s[0] == '-') {
         a = pop();
         b = pop();
         push(b - a);
      } else {
         push(atoi(s));
      }
   }

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



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

struct UndirectionalCompare
{
  bool operator() (const Edge& e, const Edge& f) const {
    if (min(e.src,e.dst) != min(f.src,f.dst))
      return min(e.src,e.dst) < min(f.src,f.dst);
    return max(e.src,e.dst) < max(f.src,f.dst);
  }
};

typedef set<Edge, UndirectionalCompare> Edgeset;
void visit(const Graph &g, int v, int u, vi& art, vector<Edgeset>& bcomp, stack<Edge>& S, vi& num, vi& low, int& time)
{
  low[v] = num[v] = ++time;
  vrep(e, g[v]) {
    int w = e->dst;
    if (num[w] < num[v]) S.push(*e);              // for bcomps
    if (num[w] == 0) {
      visit(g, w, v, art, bcomp, S, num, low, time);
      low[v] = min(low[v], low[w]);
      if ((num[v] == 1 && num[w] != 2) ||         // for arts
          (num[v] != 1 && low[w] >= num[v])) art.push_back(v);
      if (low[w] >= num[v]) {                     // for bcomps
        bcomp.push_back(Edgeset());
        while (1) {
          Edge f = S.top(); S.pop();
          bcomp.back().insert(f);
          if (f.src == v && f.dst == w) break;
        }
      }
    } else low[v] = min(low[v], num[w]);
  }
}

void ArticulationPoint(const Graph& g, vi& art, vector<Edgeset>& bcomp)
{
  const int n = g.size();
  vi low(n), num(n);
  stack<Edge> S;
  rep(u, n) if (num[u] == 0) {
    int time = 0;
    visit(g, u, -1, art, bcomp, S, num, low, time);
  }
}

int V, E;
int s, t;

int main()
{
  cin >> V >> E;
  Graph g(V);
  vi art;
  vector<Edgeset> bcomp;
  rep(i, E){
    cin >> s >> t;
    g[s].pb(Edge(s, t, 1));
    g[t].pb(Edge(t, s, 1));
  }


  ArticulationPoint(g, art, bcomp);

  sort(ALL(art));
  art.erase(unique(ALL(art)), art.end());

  vrep(v, art) cout << *v  << endl;

  return 0;
}

Measured memory_bytes: 8124
class Unionfind:
    def __init__(self, n):
        self.parents = [-1 for i in range(n)]
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]
    
    def notsame(self, x, y):
        x = self.find(x)
        y = self.find(y)
        return False if x == y else True
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        if x > y:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def belong_num(self, x):
        return -self.parents[self.find(x)]
    
N, M, K = map(int, input().split())
lists = [0 for i in range(N)]
uf = Unionfind(N)
for i in range(M + K):
    a, b = map(lambda x:int(x) - 1, input().split())
    if i < M:
        uf.union(a, b)     
    if uf.notsame(a, b) and i >= M:
        continue
    lists[a] += 1
    lists[b] += 1
    
for i in range(N):
    print(uf.belong_num(i) - lists[i] - 1, end=' ')
print()

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

int tax(int p, int x) { return x * (100 + p) / 100; }

int main() {
  while (true) {
    int x, y, s;
    cin >> x >> y >> s;
    if (!x && !y && !s)
      break;

    int ans = 0;
    for (int i = 1; i < s; i++) {
      for (int j = i; j < s; j++) {
        if (tax(x, i) + tax(x, j) == s) {
          ans = max(ans, tax(y, i) + tax(y, j));
        }
      }
    }
    cout << ans << endl;
  }
}



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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> A){
    const ll total = accumulate(A.begin(), A.end(), 0LL);
    ll count = 0;
    for(ll ai : A){
        count += (ai * 4 * M >= total);
    }
    if(count >= M){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;

int main() {
	#ifdef kvutxdy
	freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/Codeforces/input.in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	string s;
	cin>>s;
	int res=0,n=s.size();
	for(int i=1;i<n;++i) res+=s[i]!=s[i-1];
	cout<<res;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  int n;
  cin >> n;
  if(n%2 == 0) cout << n << ln;
  else cout << n*2 << ln;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
int i, j, n[10], max, temp;

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

for(i=0; i<10; i++){
max = i;
for(j = i + 1; j < 10; j++){
if(n[max] < n[j]) max = j;
}
temp = n[max];
n[max] = n[i];
n[i] = temp;

while(i==0){
cout<<temp<<endl;
break;
}
while(i==1){
cout<<temp<<endl;
break;
}
while(i==2){
cout<<temp<<endl;
break;
}

}
}


Measured memory_bytes: 3100
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int num500 = sc.nextInt();
      	int num100 = sc.nextInt();
      	int num50 = sc.nextInt();
      	int targetAmount = sc.nextInt();
      	int count = 0;
      	
      	for(int i = 0; i <= num500; i++) {
        	for(int j = 0; j <= num100; j++) {
            	for(int k = 0; k <= num50; k++) {
                	int total = 500 * i + 100 * j + 50 * k;
                  	if(total == targetAmount) count++;
                }
            }
        }
      	System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else 
    #define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int a[MX];
int b[MX];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n, x;
    cin >> n >> x;
    fi(0, n) {
        cin >> a[i];
        b[i] = BIG;
    }
    int ans = BIG;
    fi(0, n) {
        int kek = i * x;
        fj(0, n) {
            mine(b[j], a[(j - i + n) % n]);
            kek += b[j];
        }
        mine(ans, kek);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3708
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 123456;
int dp[MAXN], h[MAXN];

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    for (int i = 1; i <= N; i++) {
        scanf("%d", &h[i]);
        dp[i] = (int)1e9;
    }
    dp[1] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= K; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    printf("%d\n", dp[N]);
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h> //rooted trees
#define M 100001
typedef struct tree
{
  int p,l,r;
}t;
t T[M];
  
int main(void)
{
  int n,i,j,k,id,c,tmp,tmp2;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    {
    T[i].p=T[i].l=T[i].r=-1;
    }
  for(i=0;i<n;i++)
    {
    scanf("%d %d",&id,&k);
    for(j=0;j<k;j++)
      {
      scanf("%d",&c);
      T[c].p=id;
      if(j==0)
    T[id].l=c;
      else
    T[tmp].r=c;
      tmp=c;
    }
  }
  for(i=0;i<n;i++)
    {
    id=0;
    k=0;
    tmp=T[i].p;
    tmp2=T[i].l;
    while(tmp!=-1)
      {
      k++,tmp=T[tmp].p;
    }
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,k);
    if(T[i].p==-1)
      printf("root, [");
    else if(T[i].l!=-1)
      printf("internal node, [");
    else
      printf("leaf, [");
    while(tmp2!=-1)
      {
      if(id==0)
	{
    printf("%d",T[i].l);
    id=1;
      }
      else
    printf(", %d",tmp2);
      tmp2=T[tmp2].r;
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 1784
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

n = int(input())

a=[0]*1001  # リスト

for i in range(1,33):
    for j in range(2,10):
        k = i ** j
        if k > 1000:
            break
        else:
            a[k] = 1

for i in range(n,0,-1):
    if(a[i]==1):
        print(i)
        break





Measured memory_bytes: 22820
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0){
      break;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
      int sum=0;
      for(int j=i;j<n;j++){
	sum+=j;
	if(sum==n){
	  ans++;
	}
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3124
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX_V 100005
#define MAX_E 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

ll memo[51][51];

ll comb(ll n, ll k) {
    if(k==0) return 1;
    if(n==k) return 1;
    if(memo[n][k]!=0) return memo[n][k];
    return memo[n][k]=comb(n-1, k)+comb(n-1, k-1);
}

ll modpow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

int main(void) {
    ll N, A, B, i;
    cin >> N >> A >> B;
    double v[51];
    
    for(i=1; i<=N; i++) {
        cin >> v[i];
        v[i]=-v[i];
    }
    sort(v+1, v+N+1);
    double sum=0;
    for(i=1; i<=A; i++) {
        sum+=v[i];
    }
    ll cnt=0;
    ll j=1;
    for(i=1; i<=N; i++) {
        if(v[i]==v[A]) {
            cnt++;
            if(cnt==1) j=i;
        }
    }
    
    printf("%f\n", (-sum)/A);
    ll tmp=0;
    if(j==1) {
        for(i=A; i<=min(B, cnt); i++) {
            tmp+=comb(cnt, i);
        }
        
        prin(tmp);
    }else
        prin(comb(cnt, A-j+1));
    
}

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


int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    cin>>n;

    int a, b;
    cin>>a>>b;
    if (a%n) {
        if ((n*(a/n) + n) <= b) cout<<"OK";
        else cout<<"NG";
    }
    else{
        cout<<"OK";
    }
    
    return 0;
}



Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int count = 0;
		while ((int) Math.pow(2, count) <= n) {
			count++;
		}
		System.out.println((int)Math.pow(2, count - 1));

		sc.close();
	}
}


Measured memory_bytes: 21716
//AtCoder Regular Contest 011
//B. ルイス・キャロルの記憶術
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int inputMax = int.Parse(Console.ReadLine());
            string[] inputs = Console.ReadLine().Split(' ');
            int[] d = new int[inputMax];
            for (int i = 0; i < inputMax; i++)
            {
                d[i] = int.Parse(inputs[i]);
            }
            Array.Sort(d);
            int[] placeTimes = new int[inputMax + 1];
            placeTimes[0] = 0;
            int placeTimeMax = 1;
            int clockWiseMin = int.MaxValue, counterClockWiseMin = int.MaxValue;
            for (int i = 0; i < inputMax; i++)
            {
                clockWiseMin = int.MaxValue;
                int[] placeTimesTest = new int[placeTimeMax + 1];
                Array.Copy(placeTimes, placeTimesTest, placeTimeMax);
                placeTimesTest[placeTimeMax] = d[i];
                Array.Sort(placeTimesTest);
                for (int j = 0; j < placeTimeMax; j++)
                {
                    clockWiseMin = Math.Min(clockWiseMin, Math.Abs(placeTimesTest[j + 1] - placeTimesTest[j]));
                }
                clockWiseMin = Math.Min(clockWiseMin, Math.Abs(24 - placeTimesTest[placeTimeMax]));

                counterClockWiseMin = int.MaxValue;
                placeTimesTest = new int[placeTimeMax + 1];
                Array.Copy(placeTimes, placeTimesTest, placeTimeMax);
                placeTimesTest[placeTimeMax] = 24-d[i];
                Array.Sort(placeTimesTest);
                for (int j = 0; j < placeTimeMax; j++)
                {
                    counterClockWiseMin = Math.Min(counterClockWiseMin, Math.Abs(placeTimesTest[j + 1] - placeTimesTest[j]));
                }
                counterClockWiseMin = Math.Min(counterClockWiseMin, Math.Abs(24 - placeTimesTest[placeTimeMax]));

                //counterClockWiseMin = int.MaxValue;
                //placeTimes[placeTimeMax] = 24 - d[i];
                //for (int j = 0; j < placeTimeMax; j++)
                //{
                //    counterClockWiseMin = Math.Min(counterClockWiseMin, Math.Abs(placeTimes[j + 1] - placeTimes[j]));
                //}
                //counterClockWiseMin = Math.Min(counterClockWiseMin, Math.Abs(24 - placeTimes[placeTimeMax]));

                if (clockWiseMin > counterClockWiseMin)
                {
                    placeTimes[placeTimeMax] = d[i];
                }
                else
                {
                    placeTimes[placeTimeMax] = 24-d[i];
                }
                Array.Sort(placeTimes,0, placeTimeMax+1);
                placeTimeMax++;
                if (Math.Max(clockWiseMin, counterClockWiseMin) == 0)
                {
                    Console.WriteLine(0);
                    return;
                }
            }
            Console.WriteLine(Math.Max(clockWiseMin, counterClockWiseMin));
        }
    }
}

Measured memory_bytes: 13268
N, M = map(int, input().split())
X = []
Y = []
for _ in range(N):
    a, b = map(int, input().split())
    X.append((a, b))
for _ in range(M):
    c, d = map(int, input().split())
    Y.append((c, d))

for i in range(N):
    mi = 1<<100
    for j in range(M):
        d = abs(X[i][0] - Y[j][0]) + abs(X[i][1] - Y[j][1])
        if d < mi:
            ans = j + 1
            mi = d
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n,a,b;
    IN n >> a >> b;
    P(min(a*n,b));
    
	return  0;
}

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int dfs(vi &col, int p){
	int n = col.size();
	if(!col[p]) return 0;
	col[p] = 0;
	int res = 1 + dfs(col, (p + 1) % n);
	if((p - 1 + n) % n != (p + 1) % n) res += dfs(col, (p - 1 + n) % n);
	return res;
}

int main(){
	int n, m;
	cin >> n >> m;
	vi col(n);
	
	rep(i, m){
		int a, l; cin >> a >> l;
		rep(j, l) col[(a + j) % n] = 1;
	}
	map<int, int> ans;
	rep(i, n) if(col[i]) ans[-dfs(col, i)]++;
	
	each(i, ans) cout << -i->first << " " << i->second <<endl;
	
	return 0;
}


Measured memory_bytes: 1200
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A,B,C,D = map(int,input().split())

ans = 0
ans += B//C
ans += B//D
ans -= B//lcm(C,D)
ans -= (A-1)//C
ans -= (A-1)//D
ans += (A-1)//lcm(C,D)

print(B-A+1-ans)

Measured memory_bytes: 5048
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);

const int N = 2e5+10;

int n,k,c, L[N], R[N] ,r = 1, i;

char s[N];

int main(){
   IOS

  cin>>n>>k>>c;
  


   for(i = 1; i <= n ; i++)cin>>s[i];
	
	
   for(i = 1; i <= n and r <= k; i++){
	   if(s[i] == 'o'){
		   L[r++] = i;
			i += c;
	   }
   }
	
   for(i = n, r = k; i >= 1 and r >= 1; --i){
	   if(s[i] == 'o'){
		   R[r--] = i;
		   i -= c;
	   }
   }

   for(int i = 1; i <= k; i++){
	   if(L[i] == R[i]){
		   cout<<L[i]<<"\n";
	   }
   }


}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
	if(b&1)
		res = res * a % mod;
		a = a * a % mod;
	b >>= 1;
	}

	return res;
}



Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include <functional>
#include <queue>

using namespace std;

#define MOD 1000000007
#define INF 1050000000

int main() {
	int n; cin >> n;
	int h[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	int m = h[0];
	int ans = 1;
	for (int i = 1; i < n; i++) {
		if (m <= h[i]) {
			m = h[i];
			ans++;
		}
	}

	cout << ans << endl;





}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=[0]*100001
for i in a:
    d[i-1]+=1
s=0
for num,i in enumerate(d):
    s+=i*(num+1)

bb=[]
cc=[]
for i in range(q):
    b,c=map(int,input().split())
    bb.append(b)
    cc.append(c)

for b,c in zip(bb,cc):
    k=d[b-1]
    s+=(c-b)*k
    d[b-1]=0
    d[c-1]+=k

    print(s)

Measured memory_bytes: 23732
#include<stdio.h>

int main(void){
    int i,j;
    int n;
    int cnt = 0;
    if( scanf("%d", &n) == 1);
    for (i = 1;i < n;i++){
        for(j = 1;j < n;j++){
            if (i * j >= n){
                break;
            }
            cnt++;
        }
    }
    printf("%d\n",cnt);
}

Measured memory_bytes: 1732
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,abc[121];
	for(a=1;a<=120;a++){
		abc[a]=0;
	}
	scanf("%d",&e);
	for(f=1;f<=e;f++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		abc[a*30+b*10+c-40]+=d;
	}
	b=1;
	do{
		printf(" %d",abc[b]);
		if(b%10==0){
			printf("\n");
		}
		switch(b){
			case 30:
			case 60:
			case 90:
				printf("####################\n");
				break;
		}
		b++;
	}while(b<=120);
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 5011
#define mod 1000000007

int n, m, i, j;
char s[maxN];
ll dp[maxN][maxN];

ll poww(ll a, ll b) {
    ll ans = 1;

    while (b > 0) {
        if (b & 1) ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }

    return ans;
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d\n%s", &n, s + 1);
    m = strlen(s + 1);

    if (n < m) {
        printf("0");
        return 0;
    }

    dp[0][0] = 1;
    for (i = 0; i <= n; i++) {
        for (j = 0; j <= i; j++) {
            dp[i][j] %= mod;

            dp[i + 1][max(0, j - 1)] += dp[i][j];
            dp[i + 1][j + 1] += dp[i][j] * 2;
        }
    }

    ll aux = poww(poww(2, m), mod - 2);
    ll ans = (dp[n][m] * aux) % mod;

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 194304
#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 int long long
#define pb push_back
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int A,B;cin>>A>>B;A--;
    int aans=0;
  	if(A<0)A=0;
    if(A%2==1){
        if(A%4==1)aans++;
    }
    else{
        if(A%4==0)aans+=A;
        else aans+=(1 ^ A);
    }
    int bans=0;
    if(B%2==1){
        if(B%4==1)bans++;
    }
    else{
        if(B%4==0)bans+=B;
        else bans+=(1 ^ B);
    }
    cout<<(aans ^ bans)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string n;
    cin >> n;
    for (int i = 0; i < n.size(); i++) {
      if (n.at(i) == '1') {
        cout << '9';
      } else {
        cout << '1';
      }
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  for (int i = 0; i < n - 1; ++i) scanf("%d", &c[i]);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += b[a[i] - 1];
    if (i < n - 1 && a[i] + 1 == a[i + 1])
      sum += c[a[i] - 1];
  }
  printf("%d\n", sum);
  return 0;
}


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

int insertionSort(int* a,int n,int g) {
    int cnt = 0;
    for (int i = g; i < n; i++) {
        int v = a[i];
        int j = i - g;
        while ((j >= 0) && (a[j] > v)) {
            a[j + g] = a[j];
            j = j - g;
            cnt++;
            a[j + g] = v;
        }
    }
    return cnt;
}

int main() {
    int n;
    cin >> n;
    if (n != 1) {
        int count = 0;
        int* a = new int[n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int m = 0;
        for (int i = 0; i < 20; i++) {
            if ((n >= pow(2, i)) && (n < pow(2, i + 1))) {
                m = i + 1;
                break;
            }
        }
        int* g = new int[m];
        for (int i = m - 1; i >= 0; i--) {
            g[m - 1 - i] = pow(2, i);
            count += insertionSort(a, n, g[m - 1 - i]);
        }
        cout << m << endl;
        cout << g[0];
        for (int i = 1; i < m; i++) {
            cout << " " << g[i];
        }
        cout << endl << count << endl;
        for (int i = 0; i < n; i++) {
            cout << a[i] << endl;
        }
        cout << endl;
        delete[] a;
    }
    else {
        int count = 0;
        int a;
        cin >> a;
        cout << "1" << endl << "1" << endl << "0" << endl << a << endl;
    }
    return 0;
}


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

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

    int a,b,c;cin>>a>>b>>c;

    bool ans=false;

    for(int i=1;i<=b;i++)if((a*i)%b==c)ans=true;

    puts(ans?"YES":"NO");

    return 0;
}


Measured memory_bytes: 3644
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
int main()
{
	
	int n,i,c=0,f,j,k,l;
	cin>>n;
	int a[n],b[n];

	rep(i,0,n)
		cin>>a[i];
	rep(i,0,n)
		cin>>b[i];


	rep(i,0,n)
	{
		if(a[i]<b[i])
			break;
		else if(a[i]>b[i])
		{
			rep(i,0,n)
			{
				swap(a[i],b[i]);
			}
			break;
		}
	}

	//cout<<"Here\n";

	k = n-2;

	while(1)
	{
		for(i=0;i<n;++i)
		{
			if(a[i]!=b[i])
				break;
		}

		if(i==n)
			break;


		++c;

		f=0;

		Here:

		for(l=k+1;l<n;++l)
		{
			if(a[l]>a[l-1])
				break;
		}

		if(l==n)
		{
			--k;
			goto Here;
		}

		for(i=n-1;i>=k;--i)
		{
			for(j=i-1;j>=k;--j)
			{
				if(a[i]>a[j])
				{
					swap(a[i],a[j]);
					f=1;
					sort(a+j+1,a+n);
					k=n-2;
					break;
				}
			}

			if(f)
				break;
		}



	}


	cout<<c<<"\n";




	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.function.Function;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<A> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(new A(sc.nextInt(), sc.nextInt(), sc.next().charAt(0)));
        }
        long min = Long.MAX_VALUE;

        min = Math.min(min,
                       test(list,
                            (a, b) -> a.x - b.x,
                            a -> a.y,
                            a -> a.x,
                            'R', 'L' , 5));
        min = Math.min(min,
                       test(list,
                            (a, b) -> a.y - b.y,
                            a -> a.x,
                            a -> a.y,
                            'U', 'D' , 5));
        min = Math.min(min,
                       test(list,
                            (a, b) -> a.sum() - b.sum(),
                            a -> a.sub(),
                            a -> a.sum(),
                            'R', 'D' , 5));
        min = Math.min(min,
                       test(list,
                            (a, b) -> a.sum() - b.sum(),
                            a -> a.sub(),
                            a -> a.sum(),
                            'U', 'L' , 5));
        min = Math.min(min,
                       test(list,
                            (a, b) -> a.sub() - b.sub(),
                            a -> a.sum(),
                            a -> a.sub(),
                            'R', 'U' , 5));
        min = Math.min(min,
                       test(list,
                            (a, b) -> a.sub() - b.sub(),
                            a -> a.sum(),
                            a -> a.sub(),
                            'D', 'L' , 5));
        if(min == Long.MAX_VALUE) {
            System.out.println("SAFE");
        } else {
            System.out.println(min);
        }

    }

    static long test(List<A> list,
              Comparator<A> comparator,
              Function<A, Integer> keyFunc,
              Function<A, Integer> valueFunc,
              char forward,
              char backward, int mult) {
        long min = Long.MAX_VALUE;
        Map<Integer, Integer> map = new HashMap<>();
        list.sort(comparator);
        for(A a : list) {
            if(a.u == forward) {
                map.put(keyFunc.apply(a), valueFunc.apply(a));
            } else if(a.u == backward){
                if(map.containsKey(keyFunc.apply(a))) {
                    min = Math.min(min, (valueFunc.apply(a) - map.get(keyFunc.apply(a))) * mult);
                }
            }
        }
        return min;
    }



    static class A {

        int x;
        int y;
        char u;

        A(int x, int y, char u) {
            this.x = x;
            this.y = y;
            this.u = u;
        }

        int sum() {
            return x + y;
        }
        int sub() {
            return x - y;
        }
    }

}




Measured memory_bytes: 76144
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;
ll c[100005];
int main()
{	
	ll n,m;
	cin>>n>>m;
	ll i,l,r;
	ll m1=m;
	while(m--)
	{
		cin>>l>>r;
		c[l]+=1;
		c[r+1]-=1;
	}
	for(i=2;i<=100000;i++)
		c[i]+=c[i-1];
	ll ans=0;
	for(i=1;i<=100000;i++)
		if(c[i]==m1)
			ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll h,w,k;
	cin>>h>>w>>k;
	for(int i=0;i<=h;i++){
		ll now=i*w;
		for(int j=0;j<=w;j++){
			ll nex=(h-2*i)*j;
			if(now+nex==k){
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	// your code goes here
	return 0;
}

Measured memory_bytes: 256