akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int w[] = new int[n];
    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
    }
    int ans = 99999;
    for(int i = 0; i < n-1; i++){
      int l = 0;
      int r = 0;
      for(int j = 0; j <= i; j++){
        l += w[j];
      }
      for(int j = i+1; j < n; j++){
        r += w[j];
      }
      ans = Math.min(ans,Math.abs(l-r));
    }
    System.out.print(ans);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<string> vs;
    vector<int> vt;

    int sum = 0;

    rep(i,n){
        string s;
        int t;

        cin >> s >> t;

        vs.pback(s);
        vt.pback(t);

        sum += t;
    }

    string x;
    cin >> x;

    int tmp = 0;

    rep(i,n){

        tmp += vt[i];

        if(vs[i] == x) break;
    }

    cout << sum - tmp << endl;



    return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] top = new String[4];
		top[0] = sc.next();
		top[1] = sc.next();
		top[2] = sc.next();
		if(n == 3) {
			PriorityQueue<Data> list = new PriorityQueue<Data>();
			for(int j = 0; j < 3; j++) {
				for(int k = 0; k < 3; k++) {
					if(j == k) continue;
					list.add(new Data(top[j],top[k],j,k));
				}
			}
			list.poll();
			list.poll();
			System.out.println(list.poll().num);
			return;
		}
		top[3] = sc.next();
		
		for(int i = 4; i < n; i++) {
			PriorityQueue<Data> list = new PriorityQueue<Data>();
			String in = sc.next();
			list.add(new Data(top[0],in,0,4));
			list.add(new Data(top[1],in,1,4));
			list.add(new Data(top[2],in,2,4));
			list.add(new Data(top[3],in,3,4));
			list.add(new Data(in,top[0],4,0));
			list.add(new Data(in,top[1],4,1));
			list.add(new Data(in,top[2],4,2));
			list.add(new Data(in,top[3],4,3));
			for(int j = 0; j < 4; j++) {
				for(int k = 0; k < 4; k++) {
					if(j == k) continue;
					list.add(new Data(top[j],top[k],j,k));
				}
			}
			boolean[] use = new boolean[5];
			for(int j = 0; j < 3; j++) {
				Data tmp = list.poll();
				use[tmp.c] = true;
				use[tmp.d] = true;
			}
			if(!use[0]) top[0] = in;
			else if(!use[1]) top[1] = in;
			else if(!use[2]) top[2] = in;
			else if(!use[3]) top[3] = in;
		}
		PriorityQueue<Data> list = new PriorityQueue<Data>();
		for(int j = 0; j < 4; j++) {
			for(int k = 0; k < 4; k++) {
				if(j == k) continue;
				list.add(new Data(top[j],top[k],j,k));
			}
		}
		list.poll();
		list.poll();
		System.out.println(list.poll().num);
	}
	static class Data implements Comparable<Data>{
		int num;
		int c;
		int d;
		Data(String a, String b,int c, int d) {
			num = Integer.parseInt(a + b);
			this.c = c;
			this.d = d;
		}
		@Override
		public int compareTo(Data o) {
			return this.num - o.num;
		}
	}
	
}

Measured memory_bytes: 51612
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>q;
int n,t,ans;
signed main()
{
	int x,y;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	scanf("%lld",&x),q[x]++,ans+=x;
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld%lld",&x,&y);
		ans+=(y-x)*q[x];
		printf("%lld\n",ans);
		q[y]+=q[x];
		q[x]=0;
	}
    return 0;
}

Measured memory_bytes: 9668
#include<stdio.h>
int main()
{
	long long int n;
	scanf("%lld", &n);
	char ans[102];
	int i = 0;
	while (n > 0)
	{
		ans[i] = 'a' + ((n - 1) % 26);
		n = (n - 1) / 26;
		i++;
	}
	while (i > 0)
	{
		i--;
		printf("%c", ans[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1660
/*
AizuOnline A2408
Social
*/
#include <stdio.h>
int N,K,R;
int bunny[51]; //bunny[n] no notta fune
int monku[51]; //bunny[n] ga monku ari = T
void init()
{ int i,j,m,b,fune;
  scanf("%d %d",&N,&K);
  fune=0;
  for(i=0;i<K;i++)
    {  scanf("%d",&m);
       fune++;
       for(j=0;j<m;j++)
	{  scanf("%d",&b);
	   bunny[b] = fune;
	}
    }
}

void read_relation()
{ int i,b1,b2;

  scanf("%d" ,&R);

  for(i=0;i<R;i++)
    {   scanf("%d",&b1);
        scanf("%d",&b2);
	if(bunny[b1]==bunny[b2])
	  {  monku[b1]=1;
	     monku[b2]=1;
	  }
    }
}

int count_monku()
{ int i,cnt;
  cnt=0;   
  for(i=1;i<=N;i++)
    cnt += (monku[i])?1:0;

  return(cnt);
}
void print()
{int i; 
 for(i=1;i<=N;i++)
   printf("%d:",bunny[i]);
  printf("\n");
}


main()
{
  init(); //print();
  read_relation();

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

Measured memory_bytes: 600
#include<iostream>

using namespace std;

int main()
{
	string S;

	cin >> S;

	int i;
	int count = 0;

	for(i=0; i<4; i++){
		if(S[i] == '+') count++;
		else if(S[i] == '-') count--;
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int A,B;
  cin>>A>>B;
  int ans=1;
  rep(i,100000){
    if(i*8>=A*100&&i*8<(A+1)*100&&i>=B*10&&i<(B+1)*10){
      cout<<i<<endl;
      ans=0;
      break;
    }
  }
  if(ans) cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b) << endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  double ans=(double)a/c;
  
  if(ans<=b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

int n, m;
map<int, int> p;

int main() {
	cin >> n;
	int d;
	for (int i = 0; i < n; ++i) {
		cin >> d;
		if (p.find(d) == p.end()) p[d] = 1;
		else p[d] += 1;
	}
	cin >> m;
	int t;
	for (int i = 0; i < m; ++i) {
		cin >> t;
		if (p.find(t) != p.end() && p[t] > 0) {
			p[t] -= 1;
		}
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
int main()
{
int n,num;
scanf("%d",&n);
set <int> arr;
for(int i=0;i<n;i++)
{
scanf("%d",&num);
arr.insert(num);
}
printf("%d",arr.size());
}

Measured memory_bytes: 256
//04
#include<iostream>
#include<string>

using namespace std;

int main(){
  int n;
  cin>>n;
  cin.ignore();
  while(n--){
    string s;
    getline(cin,s);
    for(int i;(i=s.find("Hoshino"))!=string::npos;){
      s[i+6]='a';
    }
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
def check(var):
    return (0 <= var <= N) and all(c in str(var) for c in '753')


def dfs(x):
    res = 0
    if check(x): res += 1
    if x <= N:
        for v in 3, 5, 7:
            res += dfs(10 * x + v)
    return res


N = int(input())
print(dfs(0))


Measured memory_bytes: 3060
#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

int a[10][10],b[10][10],ans[10][10],dx[]={1,0,-1,0,0},dy[]={0,1,0,-1,0};

void init(void){
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      b[i][j]=a[i][j];
      ans[i][j]=0;
    }
  }
}

void rev(int x, int y){
  for(int k=0;k<5;k++){

    int ny=y+dy[k],nx=x+dx[k];

    if( 0<=ny && 0<=nx && ny<10 && nx<10)
      b[ny][nx]=!b[ny][nx];
  }
}

int ok(void){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      if(b[i][j])return 0;
  return 1;
}

void solve(int p[]){
  init();

  for(int i=0;i<10;i++){
    if(p[i])rev(i,0);
    ans[0][i]=p[i];
  }
  for(int i=1;i<10;i++){
    for(int j=0;j<10;j++){
      if(b[i-1][j]){
	rev(j,i);
	ans[i][j]=1;
      }
    }
  }

  if(ok()){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	cout << ans[i][j];
	if(j<9)cout << " ";
      }
      cout << endl;
    }
  }
}

void func(int p[], int cnt){
  if(9<cnt)solve(p);
  else {
    p[cnt]=0;
    func(p,cnt+1);
    p[cnt]=1;
    func(p,cnt+1);
  }
}

int main(void){
  int n;

  cin >> n;

  while(n--){

    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
	cin >> a[i][j];

    int p[10]={0};
    func(p,0);
  }

  return 0;
}

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

int main()
{
    size_t N;
    cin >> N;
    long long ai;
    vector<long long> a;
    for(size_t i=0; i<N; i++){
        cin >> ai;
        a.push_back(ai);
    }
    size_t nTwo = 0;
    for(auto v : a){
        while(v!=0 && v%2==0){
            nTwo++;
            v/=2;
        }
    }
    cout<<nTwo<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<limits.h>

int h, w, n;
char field[1001][1001];
int sx, sy, gx[9], gy[9];
int d[1000][1000];
const int INF = INT_MAX / 4;
int dx[] = { 0, 1, 0, -1 }, dy[] = { -1, 0, 1, 0 };

int bfs( int idx )
{
	typedef std::pair<int,int> point;
	std::queue<point> q;
	q.push( point( sx, sy ) );
	d[sx][sy] = 0;
	
	while( !q.empty() ){
	 	point p = q.front(); q.pop();
		int x = p.first, y = p.second;
		if( x == gx[idx] && y == gy[idx] ) break;
		
		for( int i = 0; i < 4; i++ ){
			int nx = x + dx[i], ny = y + dy[i];
			if( nx >= 0 && nx < w && ny >= 0 && ny < h && field[nx][ny] != 'X' && d[nx][ny] == INF ){
				d[nx][ny] = d[x][y] + 1;
				q.push( point( nx, ny ) );
			}
		}
	}

	return d[gx[idx]][gy[idx]];
}

void init_d(){
	for( int i = 0; i < w; i++ )
		for( int j = 0; j < h; j++ )
			d[i][j] = INF;

 	return;
}

int main()
{
	std::cin >> h >> w >> n;
	for( int j = 0; j < h; j++ )
		for( int i = 0; i < w; i++ )
			std::cin >> field[i][j];
			
	for( int i = 0; i < w; i++ ){
		for( int j = 0; j < h; j++ ){		
			if( field[i][j] == 'S' ){
			 	sx = i;
				sy = j;
			}
			for( int k = 1; k <= n; k++ ){
				if( field[i][j] == k + '0' ){
					gx[k-1] = i;
					gy[k-1] = j;
				}
			}
		}
	}
	
	init_d();
	
	int ans = 0;
	for( int i = 0; i < n; i++ ){
		ans += bfs( i );
		sx = gx[i];
		sy = gy[i];
		init_d();
	}
	
	std::cout << ans << std::endl;

	return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = long.Parse(Console.ReadLine());
        long[] d = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var m = long.Parse(Console.ReadLine());
        long[] t = Console.ReadLine().Split().Select(long.Parse).ToArray();

        var dic = new Dictionary<long,long>();
        for (int i = 0; i < n; i++)
        {
            if (!dic.ContainsKey(d[i])) dic.Add(d[i],1);
            else dic[d[i]]++;
        }

        var ans = "YES";
        for (int i = 0; i < m; i++)
        {
            if(!dic.ContainsKey(t[i]))
            {
                ans = "NO";
                break;
            }
            else
            {
                if(dic[t[i]] > 0)
                {
                    dic[t[i]]--;
                }
                else
                {
                    ans = "NO";
                    break;
                }
            }

        }

        // 出力
        Console.WriteLine(ans);
    }
}

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

using namespace std;

int v[50];
int main() {
    
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) 
        cin >> v[i];
    
    sort(v, v + n);
    
    long double ans = v[0];
    for (int i = 1; i < n; ++i) {
        ans += v[i];
        ans /= 2.;
    }

    printf("%.10Lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
S = gets.chomp

h = {'a'=>0, 'b' =>0, 'c'=>0}

S.each_char do |c|
  h[c] += 1
end

min = [h['a'],h['b'],h['c']].min
h.each do |k,v|
  if v - min >= 2
    puts 'NO'
    exit 0
  end
end

puts 'YES'


Measured memory_bytes: 3836
def is_prime?(n)
  return true if n == 2
  return false if n <= 1 || n.even?
  3.step(Math.sqrt(n), 2) { |x| return false if n.modulo(x).zero? }
  return true
end

n = gets.to_i
ns = []
n.times { ns << gets.to_i }
puts ns.map{ |x| lambda{|y| (is_prime?(y) ? 1 : 0) }.call(x) }.inject(&:+)

Measured memory_bytes: 6720
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct {
  int A;
  int B;
} X;
bool Aorder(const X& a, const X& b) {
  if (a.A < b.A) return true;
  if (a.A > b.A) return false;
  return a.B > b.B;
}
bool Border(const X& a, const X& b) {
  if (a.B < b.B) return true;
  if (a.B > b.B) return false;
  return a.B < b.B;
}
int main(void) {
  int N;
  cin >> N;
  vector <X> Xlist(N);
  for (int i = 0; i < N; i++) {
    cin >> Xlist[i].A >> Xlist[i].B;
  }

  if (N%2==1) {
    // odd pattern
    int midpt = N/2;
    sort(Xlist.begin(), Xlist.end(), Aorder);
    int midst = Xlist[midpt].A;
    sort(Xlist.begin(), Xlist.end(), Border);
    int miden = Xlist[midpt].B;

    int ans = miden - midst + 1;
    cout << ans << endl;
  } else {
    // even pattern
#if 0
    // 1/2を使いたくないので、2倍する
    for (int i = 0; i < Xlist.size(); i++) {
      Xlist[i].A *= 2;
      Xlist[i].B *= 2;
    }
#endif
    int midpt1 = N/2-1;
    int midpt2 = N/2;
    sort(Xlist.begin(), Xlist.end(), Aorder);
    int midst1 = Xlist[midpt1].A;
    int midst2 = Xlist[midpt2].A;
    sort(Xlist.begin(), Xlist.end(), Border);
    int miden1 = Xlist[midpt1].B;
    int miden2 = Xlist[midpt2].B;

    int stpos = (midst1+midst2);
    int enpos = (miden1+miden2);
    int ans = enpos - stpos + 1;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
ll b;
ll a;

void addedge(ll u, ll v)

	{
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

bool dfs(ll node)
	{
		cout<<node<<endl;
		mark[node]=1;
		

		for(auto i:adj[node])
		{	
			if(!mark[i])
				dfs(i);
		}			

			
	}

int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

 ll r,g,b,n;
 cin>>r>>g>>b>>n;
 ll ans=0;
 
 for(auto i=0; i<=n;i++)
 	{
 		for(auto j=0; j<=n; j++)
			{
				int k=n-i*r-j*g;
				if(k>=0 && k%b==0)
					ans++;
			}
 	}
 	cout<<ans<<endl;
}		





Measured memory_bytes: 2560
#include<cstdio>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    const ll Kmax=1e6+15;
    ll right[Kmax];
    ll left[Kmax];
    bool cmp(ll a,ll b){
    	return a>b;
    }
    int main(){
    	ll n;
    	scanf("%lld",&n);
    	for(ll i=0;i<n;i++){
    		scanf("%lld",&left[i]);
    		scanf("%lld",&right[i]);
    	}
    	sort(left,left+n,cmp);
    	sort(right,right+n);
    	long long loc=0;
    	long long ans1=0;
    	long long ans2=0;
    	for(ll i=0;i<n;i++){
    		if(loc>=left[i]){
    			break;
    		}
    		ans1+=left[i]-loc;
    		loc=left[i];
    		if(loc<=right[i]){
    			break;
    		}
    		ans1+=loc-right[i];
    		loc=right[i];
    	}if(loc<0)loc=-loc;
    	ans1+=loc;
    	
    	loc=0;

    		for(ll i=0;i<n;i++){
    		if(loc<=right[i]){
    			break;
    		}
    		ans2+=loc-right[i];
    		loc=right[i];
    		if(loc>=left[i]){
    			break;
    		}
    		ans2+=left[i]-loc;
    		loc=left[i];
    	}

    	if(loc<0)loc=-loc;
    	ans2+=loc;
    	printf("%lld\n",max(ans1,ans2));
    	return 0;
    }


Measured memory_bytes: 5120
from collections import Counter
n=int(input())
s=[input() for _ in range(n)]
c=Counter(s)
c=c.most_common()
i=0
ans=[]
for i in range(len(c)):
  if c[0][1] == c[i][1]:
    ans.append(c[i][0])

ans.sort()
for i in range(len(ans)):
  print(ans[i])

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

int main()
{
    int n, x, t;
    cin >> n >> x >> t;

    int ex;
    ex = n % x;
    if (ex == 0)
        cout << t * n / x << endl;
    else
        cout << t * (n / x + 1) << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
  int n;
  cin >> n;
  bool flg = true;
  int i=0;
  while((i<n) && (flg == true)){
    int a;
    cin >> a;
    if(a%2 == 0){
      if((a%3!=0)&&(a%5!=0)){
        flg = false;
      }
    }
    i++;
  }
  if(flg == true){
    cout << "APPROVED" << endl;
  }else{
    cout << "DENIED" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
count = 0

for i in range(N):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
    tmp = A[i]
    A[i] = A[minj]
    A[minj] = tmp
    if minj != i:
        count += 1
print(' '.join([str(a) for a in A])) 
print(count)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int a[205], G[205][205];
queue <int> q;

int main() {
    
  int n; read(n);
  for (RI i = 1; i <= n; ++i)
    for (RI j = 1; j <= n; ++j) {
      char ch = gc();
      while (ch != '0' && ch != '1') ch = gc();
      if (ch == '1') G[i][j] = 1;
    }
  int ans = 0;
  for (RI i = 1; i <= n; ++i) {
    memset(a, 0, sizeof(a));
    a[i] = 1;
    q.push(i);
    while (!q.empty()) {
      int t = q.front(); q.pop();
      for (RI i = 1; i <= n; ++i)
        if (G[t][i]) {
          if (!a[i]) a[i] = a[t] + 1, q.push(i);
          else if (abs(a[i] - a[t]) != 1) return puts("-1"), 0;
        }
    }
    for (RI j = 1; j <= n; ++j)
      ans = max(ans, a[j]);
  }
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 512
A,B,C,X,Y = map(int,input().split())

C2 = C * 2
diff = abs(X - Y)

ans = 0


if C2 > A + B:
  ans = (A * X) + (B * Y)

elif C2 <= A + B:
  if X > Y:
    ans = min(C2 * Y + A * diff,C2 * X)

  else:
    ans = min(C2 * X + B * diff,C2 * Y)
    
print(ans)

Measured memory_bytes: 3064
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    INF = 10**10
    DP = [INF]*N
    DP[0] = 0
    DP[1] = abs(h[1]-h[0])
    for i in range(2,N):
        DP[i] = min(DP[i-j] + abs(h[i-j]-h[i]) for j in range(1,min(K,i)+1))
    print(DP[-1])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 20664
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

int main(void){

char num_str[1002];

int num;

long sum = 0;

int i;

char tmp;

while (1){

fgets(num_str,sizeof(num_str),stdin);

if (num_str[0] =='0') break;

for (i = 0;

i < strlen(num_str)-1; i++){

tmp = num_str[i];

num = atoi(&tmp);

sum = sum + num;

} 

printf("%ld\n",sum);

sum = 0;

memset(num_str,1002, 0);

}

return 0;

}

Measured memory_bytes: 532
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int p, q, r;
    cin >> p >> q >> r;
    int ans = min(p + q, p + r);
    chmin(ans, q + r);
    cout << ans << endl;
}

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

public class Main {
	private final byte MASK_RIGHT = 0x0F;//右4bit数値化用マスク
	private int[][] paper = new int[10][10];//都合の良い方眼紙

	public static void main(String[] args) throws Exception {
		new Main().execute();
	}

	private void execute() throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 128);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & MASK_RIGHT, sLine.charAt(2) & MASK_RIGHT, sLine.charAt(4) & MASK_RIGHT);
		}
		calcResult();
	}

	/**
	 *都合の良い滴下
	 */
	private void droppingInk(int x, int y, int size) {
		sinking(x, y - 1);
		sinking(x - 1, y);
		sinking(x, y);
		sinking(x + 1, y);
		sinking(x, y + 1);
		if (size == 1) {
			return;
		}

		sinking(x - 1, y - 1);
		sinking(x + 1, y - 1);
		sinking(x - 1, y + 1);
		sinking(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		sinking(x, y - 2);
		sinking(x - 2, y);
		sinking(x + 2, y);
		sinking(x, y + 2);
	}

	/**
	 * 床は汚さないようにする
	 */
	private void sinking(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			paper[x][y]++;
		}
	}

	/**
	 *紙の染みを数え、損害を報告する
	 */
	private void calcResult() {
		int white = 0;//綺麗な部分
		int max = 0;//一番ひどい汚れ
		for (int[] row : paper) {
			for (int colum : row) {
				if (colum == 0) {
					white++;
				} else if (colum > max) {
					max = colum;
				}
			}
		}
		System.out.println(white);
		System.out.println(max);
	}
}

Measured memory_bytes: 16848
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  string b;
  cin >> b;

  map<char, char> mp;
  mp['A'] = 'T';
  mp['T'] = 'A';
  mp['C'] = 'G';
  mp['G'] = 'C';

  for (int i = 0; i < b.size(); i++) {
    cout << mp[b[i]];
  }
  cout << endl;
  return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    rep(i,n){
        int a;
        cin >> a;
    }
    for(int i = 0;;++i){
        if(i*(k-1)+ 1 >= n){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    long long a = 100;
    long long x; cin >> x;
    long long ans = 0;
    while (a < x) {
        a *= 1.01;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3180
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;

int main(){
    int y,m,d;
    scanf("%d/%d/%d",&y,&m,&d);
    if(y<2019) cout<<"Heisei";
    else if(y==2019) if(m<=4) cout << "Heisei";
    else cout<<"TBD";
}

Measured memory_bytes: 256
S = input()
N = len(S)
   
S2 = S[:((N-1)//2)]
S3 = S[(N+3)//2 -1 :]  

if S == S[::-1] and S2==S2[::-1] and S3 ==S3[::-1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val tree = Array.fill[List[(Int, Int)]](N+1)(Nil) // (to, ind)
  for (i <- 1 to N-1) {
    val a, b = in.next().toInt
    tree(a) = (b, i) :: tree(a)
    tree(b) = (a, i) :: tree(b)
  }

  //
  val color = tree.map(_.length).max
  val ans = new Array[Int](N)

  case class Node(n: Int, preColor: Int)
  val stack = new Stack[Node]()

  var _color = 1
  for ((e, i) <- tree(1)) {
    ans(i) = _color
    val node = Node(e, _color)
    _color += 1
    stack.push(node)
  }

  while (!stack.isEmpty) {
    val Node(n, preColor) = stack.pop()

    var color = 1

    for ((e, ind) <- tree(n) if ans(ind) == 0) {
      if (color == preColor)
        color += 1

      val node = Node(e, color)
      stack.push(node)

      ans(ind) = color
      color += 1
    }

  }

  pw.println(color)
  ans.drop(1).foreach(pw.println)

  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 62332
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int N=1e6+10;
int n,q[N],ans;char s[N],t[N];
int main(){
    scanf("%d%s%s",&n,s+1,t+1);
    int flag=0;
    rep(i,1,n) if(s[i]^t[i]){flag=1;break;}
    if(!flag) return puts("0"),0;
    int i=n,j=n,l=1,r=0;
    while(i){
        while(i>1&&t[i]==t[i-1]) --i;
        //printf("%d %d\n",i,j);
        while(j&&(s[j]!=t[i]||j>i)) --j;
        if(!j) return puts("-1"),0;
        while(l<=r&&q[l]-(r-l+1)>=i) ++l;
        if(i!=j) q[++r]=j;
        ans=max(ans,r-l+2);--i;
    }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;

int a, b;
vector<int> v;

void solve(int x, int y, int s, int d) {

    if(x == a && y == b) {
        v.push_back(s);
    }

    if(x == 5 && y < 4) {
        return;
    } else if(y == 5 && x < 4) {
        return;
    } else if(x + y == 10) {
        return;
    } else {
        if(x + 1 <= a) solve(x + 1, y, s | 1 << (a + b - 1) - d, d + 1);
        if(y + 1 <= b) solve(x, y + 1, s, d + 1);// | 1 << (a + b - 1) - d, d + 1);
    }

}

int main() {

    cin >> a >> b;

    solve(0, 0, 0, 0);

    sort(v.begin(), v.end(), greater<int>());

    if(!(a == 0 && b == 0)) {
        for(int i = 0; i < v.size(); ++i) {
            for(int j = (a + b) - 1; j >= 0; --j) {
                if((v[i] >> j) & 1) {
                    cout << "A";
                } else {
                    cout << "B";
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const int INF=1e9;

int n;

int main(){
  cin>>n;
  map<string,int> t;
  int m=1;
  rep(j,n){
    string s;
    cin>>s;
    t[s]++;
    m=max(m,t[s]);
  }
  
  vector<string> ans;
    for (auto iter = t.begin(); iter != t.end(); iter++) {
    if(iter->second==m){
      ans.push_back(iter->first);
    }
  }
  
  sort(ans.begin(),ans.end());
  for (auto a : ans){
    cout<<a<<endl;
    
  }
  

}

Measured memory_bytes: 28528
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}


int main(){
  ll n; cin >> n;
  auto table = prime_factorize(n); ll ans = 0;

  for(auto p : table){
    ll num = p.second; ll cnt = 0;
    for(ll i=1; i <= 60; i++){
      if(num >= i){
        cnt++;
        num -= i;
      }
      else break;
    }
    
    ans += cnt;
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 INF = std::numeric_limits<i64>::max();
constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
const string NO = "IMPOSSIBLE";
const i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

void solve(long long A, long long B){
    if(A % 2 != B % 2) cout << NO << endl;
    else cout << (max(A, B) - min(A, B)) / 2 + min(A, B) << endl;
}

int main() {
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<queue>
#include<string>
#include<cstring>


using namespace std;
typedef long long LL;
const int maxn=2e6+7;
LL n;
LL tot=0;
LL a[maxn];
LL bit[maxn];

struct node {
LL val,pos;
}arr[maxn];

bool cmp(node n1,node n2)
{
    return n1.val==n2.val?n1.pos<n2.pos:n1.val<n2.val;
}

void update(LL x,LL val)
{
    for(; x< maxn ;x+=(x & -x))
    {
        bit[x]+=val;
    }
}

LL getsum(LL x)
{
    LL ans=0;
    for(;x>0;x-=(x & -x))
    {
        ans += bit[x];
    }
    return ans;
}



bool check(LL x){
    memset(bit,0,sizeof(bit));
     memset(arr,0,sizeof(arr));


	for(int i=1;i<=n;i++)
    {
        if(a[i]<=x)arr[i].val=-1;
        else arr[i].val=1;
        arr[i].pos=i+1;
    }

    arr[0].val=-1;
	arr[0].pos=1;


	for(int i=1;i<=n;i++)
	arr[i].val+=arr[i-1].val;
	sort(arr,arr+n+1,cmp);

	LL ans=0;

	for(int i=0;i<=n;i++)
    {
        ans+=(i-getsum(arr[i].pos));
        update(arr[i].pos,1);
    }

//    for(int i=0;i<=n;i++)
//	for(int j=i+1;j<=n;j++)
//    {
//
//        if(arr[j].val-arr[i].val<0)
//        {
//            cout<<"INV::"<<arr[j].val<<"   "<<arr[i].val<<endl;
//             ans++;
//        }
//    }

	//printf("ans::%lld --- x ::%lld\n",ans,x);

	return ans*2 > tot;
}


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


   for(int i=1;i<=n;i++)
    {
   	 scanf("%lld",&a[i]);
   	 tot+=i;
   }

   LL l=0,r=1e9+7;
   while(r-l>1)
    {
   	  LL mid=(l+r)/2;
   	 if(check(mid)) r=mid;
   	 else l=mid;
   	 //printf("s%d",mid);
   }
   printf("%lld\n",r);

   return 0;
}


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

public class Main{

	void run() {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String inputString;

		try{
			while((inputString=br.readLine())!=null){
				// inputs.length = 6ツづ債陛崢湘伉つウツづェツづつ「ツづゥ
				if(inputString.length()==0)
					break;
//				double[] inputs=stringsToDoubles(inputString.split(" "));
				String[] s=inputString.split(" ");
				double []inputs=new double[6];
				for(int i=0; i<6; i++)
					inputs[i]=Double.parseDouble(s[i]);

				// ツ係ツ青板行ツ療ア
				double[][] matrix={{inputs[0], inputs[1]}, {inputs[3], inputs[4]}};
				// ツ陛サツ津カツ篠ョツ右ツ陛督づ個ベツクツトツδ仰表ツ記
				double[] vector={inputs[2], inputs[5]};
				// ツ係ツ青板行ツ療アツづ個行ツ療アツ篠ョ
				double det=matrix[0][0]*matrix[1][1]-matrix[0][1]*matrix[1][0];
				// ツ係ツ青板行ツ療アツづ個逆ツ行ツ療ア
				double[][] inverse={{matrix[1][1]/det, -1*matrix[0][1]/det},
						{-1*matrix[1][0]/det, matrix[0][0]/det}};
				// ツ嘉ー
				double[] solution={inverse[0][0]*vector[0]+inverse[0][1]*vector[1],
						inverse[1][0]*vector[0]+inverse[1][1]*vector[1]};
				System.out.printf("%1.3f %1.3f\n", solution[0]+0.00005, solution[1]+0.00005);
			}
		}catch(IOException e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void main(String args[]){
		new Main().run();
	}

	private double[] stringsToDoubles(String[] s){
		double[] results = new double[6];

		for(int i=0; i<6; i++)
			results[i]=Double.parseDouble(s[i]);

		return results;
//		return new double[6];
	}

}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    
    boolean hantei = false;
    for(int i=1; i<b; i++) {
      if(a*i%b==c) {
        hantei = true;
        break;
      }
    }

    System.out.println(hantei == true?"YES":"NO");
  }
}

Measured memory_bytes: 32640
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Frog 1
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int hs[MAX_N], dp[MAX_N];

/* subroutines */

/* main */

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

  fill(dp, dp + n, INF);
  dp[0] = 0;

  for (int i = 0; i < n; i++)
    for (int j = 1; j <= 2 && i + j < n; j++) {
      int d = dp[i] + abs(hs[i + j] - hs[i]);
      if (dp[i + j] > d) dp[i + j] = d;
    }

  printf("%d\n", dp[n - 1]);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b,c;
  cin>>a>>b>>c;
  int A=a.size();
  int B=b.size();
  int C=c.size();
  int asi=0;
  int bsi=0;
  int csi=0;
  char turn='a';
  char win;
  
  while(1){
    if(turn=='a'){
      if(asi==A){
        win='A';
        break;
      }
      turn=a[asi];
      asi++;
      continue;
    }
    if(turn=='b'){
      if(bsi==B){
        win='B';
        break;
      }
      turn=b[bsi];
      bsi++;
      continue;
    }
     if(turn=='c'){
    if(csi==C){
        win='C';
        break;
      }
      turn=c[csi];
      csi++;
       continue;
    }
  }
  cout<<win<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
    	if(c=='-') f=-1;
    	c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
#define maxn 105
int n;
struct eage{
	int u,v;
}e[maxn*maxn];
int vis[maxn];
int main(){
    n=read();
    if(n&1){
    	for(int i=1;i<=n/2;i++) vis[i]=vis[n-i]=i;
    	vis[n]=n/2+1;
    	int np=0;
    	for(int i=1;i<=n;i++){
    		for(int j=i+1;j<=n;j++){
    			if(vis[j]==vis[i]) continue;
    			e[++np]=(eage){i,j};
			}
		}
		printf("%d\n",np);
		for(int i=1;i<=np;i++) printf("%d %d\n",e[i].u,e[i].v);
	}
	else{
		for(int i=1;i<=n/2;i++) vis[i]=vis[n+1-i]=i;
		int np=0;
		for(int i=1;i<=n;i++){
    		for(int j=i+1;j<=n;j++){
    			if(vis[j]==vis[i]) continue;
    			e[++np]=(eage){i,j};
			}
		}
		printf("%d\n",np);
		for(int i=1;i<=np;i++) printf("%d %d\n",e[i].u,e[i].v);
	}
    
	return 0;
}

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

#define ll long long
#define MOD 1000000007


int main(){
    int h,w;
    cin>>h>>w;

    vector<string> t(h);

    for(int i=0;i<h;i++)cin>>t.at(i);

    vector<int> H(h,0);
    vector<int> W(w,0);

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(t.at(i).at(j)=='#'){
                H.at(i) = 1;
                W.at(j) = 1;
            }
        }
    }

    int d;
    for(int i=0;i<h;i++){
        d=0;
        for(int j=0;j<w;j++){
            if(H.at(i)==1&&W.at(j)==1){
                cout<<t.at(i).at(j);
                d=1;
            }
        }
        if(d!=1)continue;
        cout<<endl;
    }

}



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


struct edge{
  int to, cost;
};
vector<edge> G[100005];
vector<bool> seen(100005, false);
vector<int> ans(100005, 0);
vector<int> sum1(100005, 0);

void dfs(int v, int sum){
  for(int i=0;i<G[v].size();i++){
    edge e = G[v][i];
    if(seen[e.to]) continue;
    seen[e.to] = true;
    sum1[e.to] = sum1[v] + e.cost;
    ans[e.to] = sum1[e.to] % 2;
    dfs(e.to, sum);
  }

  return;
}


signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  rep(i, N-1){
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    G[x].push_back((edge){y, z});
    G[y].push_back((edge){x, z});
  }
  seen[0] = true;
  dfs(0, 0);
  rep(i, N){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 11008
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	set<int> ST;

	rep(i, N) {
		int a;
		cin >> a;
		ST.insert(a);
	}

	if (ST.size() == N) co("YES");
	else co("NO");


	Would you please return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

LL n, k, b[40], dp[2];

int main() {
	cin >> n >> k;
	inc(i, n) {
		LL a;
		cin >> a;
		inc(j, 40) { b[j] += bit(a, j); }
	}
	
	inc(i, 40) {
		LL dp0 = exchange(dp[0], 0);
		LL dp1 = exchange(dp[1], 0);
		LL s0 =      b[i]  * (1LL << i);
		LL s1 = (n - b[i]) * (1LL << i);
		LL B = 1 - bit(k, i);
		
		setmax(dp[0], dp0 + s0);
		setmax(dp[B], dp0 + s1);
		setmax(dp[B], dp1 + s0);
		setmax(dp[1], dp1 + s1);
	}
	
	cout << dp[0] << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    int n;
    cin >> n;
    int left = n / 1.08;
    int right = (n+1) / 1.08;
    if (int(left*1.08) == n) cout << left << endl;
    else if (int(right*1.08) == n) cout << right << endl;
    else cout << ":(" << endl;
     
    return 0;
}

Measured memory_bytes: 256
x,y=map(int,input().split())
if (x<0 and y<0 or x>0 and y>0) and y<x:
  print(abs(x-y)+2)
elif x>=0 and y<=0:
  print(abs(abs(x)-abs(y))+1)
elif x<0 and y>0 and y>x:
    print(abs(abs(x)-abs(y))+1)
else:
    print(y-x)

Measured memory_bytes: 3064
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
A = LI()
"""
i番目を抜く時、iとi-1,iとi+1の距離を全体から引いて、そこにi-1とi+1の距離を足す
"""
A = [0] + A + [0]
total = 0
diff1 = []
diff2 = []
for aidx in range(len(A)):
    if aidx == 0:
        continue
    total += abs(A[aidx]-A[aidx-1])
    if aidx == len(A)-1:
        break
    diff1.append(abs(A[aidx] - A[aidx-1])+abs(A[aidx+1] - A[aidx]))
    diff2.append(abs(A[aidx-1] - A[aidx+1]))
#  print(total, diff1, diff2)
for aidx in range(N):
    print(total-diff1[aidx]+diff2[aidx])


Measured memory_bytes: 96344