akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define rep0(i,n) for(ll i=0;i<n;i++)
using namespace std;

const int mod = 1e9+7;
const int N = 10000003;
int prime[N];
unordered_map <ll, ll> max_map;

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

void solve(){
 	
 	int n;
 	cin >> n;
 	vector <int> a(n);
 	rep0(i,n) cin >> a[i];

 	int ans = 0, idx = 1;
 	rep0(i,n){
 		if(a[i] == idx){
 			ans++;
 			idx++;
 		}
 	}
 	if(idx == 1){
 		cout << -1;
 		return;
 	}
 	cout << n-ans;

	return;
}


int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		solve();
		// cout << "\n";
	}

	// cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
inline ll read(){ll x=0,f=1;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-48;return x*f;}
inline void write(ll x){if(x>9)write(x/10);putchar('0'+x%10);}
inline void writeln(ll x){write(x);puts("");}
ll a[N],b[N],c[N];
ll sa[N],sb[N],sc[N];
ll n;
int main()
{
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		sa[i]=1;
	}
	for(int i=1;i<=n;i++)
		b[i]=read();
	for(int i=1;i<=n;i++)
		c[i]=read();
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	for(int i=1;i<=n;i++)
		sa[i]+=sa[i-1];
	for(int i=1;i<=n;i++){
		int k=lower_bound(a+1,a+n+1,b[i])-a-1;
		sb[i]=sa[k];
	}
	for(int i=1;i<=n;i++)
		sb[i]+=sb[i-1];
	for(int i=1;i<=n;i++){
		int k=lower_bound(b+1,b+n+1,c[i])-b-1;
		sc[i]=sb[k];
	}
	for(int i=1;i<=n;i++)
		sc[i]+=sc[i-1];
	writeln(sc[n]);
	return 0;
}

Measured memory_bytes: 4992
Public Class Program
  Shared Sub Main()
    Dim s As Long = Long.Parse(Console.ReadLine())
    ' (x1, y1) = (0, 0) , (x2, y2) = (1000000000, 1) とする '
    Dim x2 As Long = 1000000000
    Dim y3 As Long = s \ x2
    Dim x3 As Long = x2 * y3 - s
    If y3 = 0 Then 
      x3 = s
    ElseIf x3 < 0 Then
      y3 += 1
      x3 = x2 * y3 - s
    End If
    Console.WriteLine("0 0 1000000000 1 " & x3.ToString() & " " & y3.ToString())
  End Sub
End Class


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

int cost[101][101];
int mincost[101];
bool used[101];
const int INF = 100000000;
int n,m;

int prim() {
  for ( int i = 0; i < n; ++i ) {
    mincost[i] = INF;
    used[i] = false;
  }
  
  mincost[0] = 0;
  int res = 0;

  while(true) {
    int v = -1;
    for ( int u = 0; u < n; u++ ) {
      if ( !used[u] && ( v == -1 || mincost[u] < mincost[v])) v = u;
    }
    
    if ( v == -1 ) break;
    used[v] = true;
    res += mincost[v];

    for ( int u = 0; u < n; u++ ) {
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  return res;
}

int main() {
  while(cin >> n >> m, n||m) {
    for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	cost[i][j] = INF;
      }
    }
    for (int i = 0; i < m; i++ ) {
      int a,b,c; cin >> a >> b >> c;
      cost[a][b] = cost[b][a] = c;
    }
    int ans = prim();
    cout << ans << endl;
  }

  return 0;
}

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

int n, ma, mb, dp[41][401][401];
int a[40], b[40], c[40];

int main() {
	cin >> n >> ma >> mb;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= 400; j++) {
			for (int k = 0; k <= 400; k++) {
				dp[i][j][k] = INT32_MAX;
			}
		}
	}

	dp[0][0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 400; j++) {
			for (int k = 0; k <= 400; k++) {
				if (dp[i][j][k] != INT32_MAX) {
					dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
					if (j + a[i] <= 400 && k + b[i] <= 400) {
						dp[i + 1][j + a[i]][k + b[i]] = min(dp[i][j][k] + c[i], dp[i + 1][j + a[i]][k + b[i]]);
					}
				}
			}
		}
	}

	int ans = INT32_MAX, i = 1;
	while (ma*i <= 400 && mb*i <= 400) {
		ans = min(ans, dp[n][ma*i][mb*i]);
		i++;
	}

	cout << ((ans == INT32_MAX)?-1:ans) << endl;
}

Measured memory_bytes: 25984
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<ll, ll>P;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void SAY(bool YES){cout<<(YES?"YES":"NO")<<endl;};
void Say(bool Yes){cout<<(Yes?"Yes":"No")<<endl;};

const ll MOD = 1000000007;

int main(){

    char a, b;
    cin >> a >> b;
    if(a == 'H')cout << b << endl;
    else if(b == 'H')cout << 'D' << endl;
    else cout << 'H' << endl;


    return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    loop {
        let v = read_vec::<String>();
        let a = v[0].parse::<i32>().unwrap();
        let op = v[1].chars().nth(0).unwrap();
        let b = v[2].parse::<i32>().unwrap();;

        let ans = match op {
            '+' => a + b,
            '-' => a - b,
            '*' => a * b,
            '/' => a / b,
            '?' => break,
            _ => continue,
        };
        println!("{}", ans);
    }
}



Measured memory_bytes: 5032
//By Koios1143
#include<bits/stdc++.h>
#define LL long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pii pair<int,int>
using namespace std;
const int MaxN = 100005;
int n,arr[MaxN][3],dp[MaxN][3];
int px[3][2]={{1,2},{0,2},{0,1}};
int main(){
	IOS
	while(cin>>n){
		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<3 ; j++){
				cin>>arr[i][j];
				dp[i][j]=0;
			}
		}
		dp[0][0]=arr[0][0];
		dp[0][1]=arr[0][1];
		dp[0][2]=arr[0][2];
		for(int i=1 ; i<n ; i++){
			for(int j=0 ; j<3 ; j++){
				for(int k=0 ; k<2 ; k++){
					dp[i][j]=max(dp[i][j],dp[i-1][px[j][k]]+arr[i][j]);
				}
			}
		}
		int ans=0;
		for(int i=0 ; i<3 ; i++){
			ans=max(ans, dp[n-1][i]);
		}
		cout<<ans<<"\n";
	}
	return 0;
}


Measured memory_bytes: 5920
s=input()
K=int(input())
N=len(s)
tmp=set()

for i in range(N):
  for j in range(K):
    t= s[i:i+j+1]
    #print(i,j,t)
    tmp.add(t)
    
lis=sorted(tmp)
#print(lis)
print(lis[K-1])


Measured memory_bytes: 4464
#include<stdio.h>
int main(void)
{
  int sets;
  int i;
  scanf("%d",&sets);
  for(i=0;i<sets;i++){
    int hen[3];
	scanf("%d %d %d",&hen[0],&hen[1],&hen[2]);
	if(hen[0]<hen[1]){
	  int tmp;
	  tmp=hen[0];
	  hen[0]=hen[1];
	  hen[1]=tmp;
	}
	if(hen[0]<hen[2]){
	  int tmp;
	  tmp=hen[0];
	  hen[0]=hen[2];
	  hen[2]=tmp;
	}
	
    if(hen[0]*hen[0]==hen[1]*hen[1]+hen[2]*hen[2])
	  puts("YES");
	else
	  puts("NO");
  }

  return 0;
}

Measured memory_bytes: 580
A, B, C, D, E, F = map(int, input().split())

A *= 100
B *= 100

M = -float('inf')
Mwater, Msugar = 0, 0
for a in range(0, F + 1, A) :
    for b in range(0, F - a + 1, B) :
        for c in range(0, F - a - b + 1, C) :
            for d in range(0, F - a - b - c + 1, D) :
                if a + b + c + d == 0 :
                    continue
                if c + d <= (a + b) * E // 100 :
                    if 100 * (c + d) / (a + b + c + d) > M :
                        M = 100 * (c + d) / (a + b + c + d)
                        Mwater = a + b
                        Msugar = c + d
                        
print(Mwater+Msugar, Msugar)

Measured memory_bytes: 42476
import java.io.*;
import java.util.*;
public class Main {


    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        long n = sc.nextLong();
        long k = sc.nextLong();
        long val = n%k;
        val=Math.min(val,Math.abs(k-val));
        pw.println(val);
        pw.flush();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }

}

Measured memory_bytes: 23124
import java.util.*;
public class Main{
    public static void main(String[] args){
        int count=0;
        int i,j,k,n,x;
        Scanner sc=new Scanner(System.in);
        while(true){
            n=sc.nextInt();
            x=sc.nextInt();
            if(n==0 && x==0) break;
            for(i=1;i<=n;i++){
                for(j=i+1;j<=n;j++){
                    for(k=j+1;k<=n;k++){
                        if(i+j+k==x){
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
            count=0;
        }
    }
}


Measured memory_bytes: 26376
#include<stdio.h>

int main(){
    int i,n,cnt,j,f;
    char s[201];

    scanf("%d",&n);
    while(n--){
        scanf("%s",s);
        if(s[0]!='>')puts("NA");
        else{
            if(s[1]!='\''&&s[1]!='^')puts("NA");
            else if(s[1]=='\''){
                for(f=0,cnt=0;s[2+cnt]!='#';cnt++){
                    if(s[2+cnt]!='='){
                        f=1;
                        break;
                    }
                }
                if(f||!cnt){
                    puts("NA");
                    continue;
                }
                for(i=0;i<cnt;i++){
                    if(s[3+cnt+i]!='='){
                        f=1;
                        break;
                    }
                }
                if(f){
                    puts("NA");
                    continue;
                }
                if(s[3+cnt+i]=='~'&&s[4+cnt+i]=='\0'){
                    puts("A");
                    continue;
                }else{
                    puts("NA");
                    continue;
                }
            }else{
                for(i=2,f=0;1;i+=2){
                    if(s[i]=='~'&&s[i+1]=='~'){
                        if(i==2){
                            puts("NA");
                            f=1;
                            break;
                        }else{
                            puts("B");
                            f=2;
                            break;
                        }
                    }
                    if(s[i]!='Q'||s[i+1]!='='){
                        puts("NA");
                        break;
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 584
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=100000+10;

int n,m,a[N]; ll x[N];

void add(int l,int r,int s,int d) {
	int e=s+(r-l)*d;
	x[l]+=s,x[l+1]+=d-s;
	x[r+1]-=d+e,x[r+2]+=e;
}

int main() {
	n=read(),m=read();
	for (int i=1;i<=n;++i) a[i]=read();
	ll sum=0;
	for (int i=2;i<=n;++i) {
		if (a[i-1]<=a[i]) {
			sum+=a[i]-a[i-1];
			add(a[i-1]+1,a[i],0,1);
		} else {
			sum+=m-a[i-1]+a[i];
			add(a[i-1]+1,m,0,1),add(1,a[i],m-a[i-1],1);
		}
	}
	for (int i=1;i<=m;++i) x[i]+=x[i-1];
	for (int i=1;i<=m;++i) x[i]+=x[i-1];
	ll mx=0;
	for (int i=1;i<=m;++i) mx=max(mx,x[i]);
	printf("%lld\n",sum-mx);
	return 0;
}

Measured memory_bytes: 4788
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf

#define sf scanf

#define ALL(x) x.begin(),x.end()
#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
int ext_gcd(int a, int b, int & x, int & y) {
    //for finding modular inverse
    //if its return 1 ,then a has a mod inverse x mod b.
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = ext_gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int main()

{
    IOS;
    //freopen("input.txt", "r", stdin);
     //freopen("output.txt", "w", stdout);
     string s;
     cin>>s;
     rep(i,s.size()-1){
        if(s[i]!=s[i+1]){
            cout<<"Yes"<<endl;
            return 0;
        }
     }
     cout<<"No"<<endl;

     return 0;

}
///Alhamdulillah


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
using namespace std;
class ATrain {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, i;
	    cin >> N >> i;
	    cout << N + 1 - i << endl;

	}
};


int main() {
	ATrain solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>

#define rep(p,q) for(int i = p;i < q;i++)

using namespace std;

const int cons = 1e9+7;


//D

bool isNotAGC(string str) {
	if (str.find("AGC") != string::npos) return false;
	rep(1, str.length()) {
		swap(str[i], str[i - 1]);
		if(str.find("AGC") != string::npos) return false;
		swap(str[i], str[i - 1]);
	}
	return true;
}

int main(void) {
	map<string,int> DP[101];
	int n;
	cin >> n;
	long long  ans = 0;
	string atcg = "ATCG";
	string baseStr[64];
	int index = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				baseStr[index] = "";
				baseStr[index] += atcg[i];
				baseStr[index] += atcg[j];
				baseStr[index] += atcg[k];
				index++;
			}
		}
	}
	rep(0, 64) {
		if (isNotAGC(baseStr[i])) {
			DP[3][baseStr[i]] = 1;
		}		
	}
	rep(4, n+1) {
		for (int j = 0; j < 64; j++) {
			for (int k = 0; k < 4; k++) {
				string combined = baseStr[j];
				combined += atcg[k];
				if (isNotAGC(combined)) {
					DP[i][baseStr[j].substr(1, 3) + atcg[k]] += DP[i-1][baseStr[j]] % cons;
					DP[i][baseStr[j].substr(1, 3) + atcg[k]] %= cons;
				}
			}
		}
	}
	rep(0, 64) {
		ans += DP[n][baseStr[i]];
		ans %= cons;
	}
	cout << ans << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,ans=1;
        cin>>n;
        ll A[n];
        for(ll i=0;i<n;i++)
        {
            cin>>A[i];
            //cout<<A[i];
        }
        //cout<<findlcm(A,n);
        for(ll i=0;i<n;i++) 
        {
            ans=lcm(ans,A[i]);
        }
        cout<<ans;
    } 
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool f[100009];

int main(){
  int n,k;
  int r,s,p;
  string t;
  cin>>n>>k;
  cin>>r>>s>>p;
  cin>>t;
  ll sum=0;

  for(int i=0;i<k;i++){
    for(int j=i;j<n;j+=k){
      if(j>=k&&t[j]==t[j-k]&&f[j-k]==0){
	f[j]=true;
	continue;
      }
      if(t[j]=='r'){
	sum+=p;
      }
      else if(t[j]=='s'){
	sum+=r;
      }
      else{
	sum+=s;
      }
    }
  }

  /*for(int i=0;i<n;i++){
    cout<<f[i]<<endl;
    }*/
  cout<<sum<<endl;
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    map<int,int> ex;
    bool check = true;

    for(int i=1; ; i++){
        int tmp;
        tmp = a * i % b;
        if(tmp == c){
            break;
        }else if(ex.count(tmp) == 0){
            ex[tmp];
        }else if(ex.count(tmp) == 1){
            check = false;
            break;
        }
    }
    if(check){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()

int main() {
    string s;
    cin >> s;
    map<char, int> map;
    bool dif = true;
    for (char c: s) {
        if (map[c] > 0) dif = false;
        map[c]++;
    }
    if (dif) printf("yes\n");
    else printf("no\n");
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int MAXN = 200005;
int A[MAXN];
int main(){

	int N, K;
	scanf("%d %d", &K, &N);
	for ( int i=0; i < N; ++i )
		scanf("%d", A + i);
	A[N] = A[0] + K;
	int best = 0;
	for ( int i=0; i < N; ++i )
		if ( best < (A[i+1] - A[i]) )
			best = A[i + 1] - A[i];
	printf("%d\n", K - best);

	return 0;
}


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

long long A[2 * 100005];

int main() {
    int N;
    long long count = 0, now = 0, l, r = 0;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    for (l = 0; l < N; l++) {
        while (r < N && (now ^ A[r]) == now + A[r]) {
            now ^= A[r++];
            count++;
        }
        count += r - l - 1;
        now ^= A[l];
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

int main() {
    std::ios::sync_with_stdio(false);  
    std::cin.tie(nullptr);  
    int N;
    std::string s;
    std::cin >> N >> s;
    int red = 0;
    int blue = 0;
    for (char c : s) {
        if (c == 'R') {
            red++;
            continue;
        }
        blue++;
    }
    std::cout << ((red > blue) ? "Yes" : "No") << std::endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
//(ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9 + 7;
    int n, k, ans = 1, cnt = 1;
    set<int> st;
    cin >> n >> k;
    vector<int> vec(n);
    vector<int> memo(n,0);
    rep(i, n) {
        cin >> vec[i];
        if(i){
            if(vec[i-1]<vec[i])cnt++;
            else cnt=1;
            if(k<=cnt)memo[i]=1;
        }
    }
    rep(i, k) {
        st.insert(vec[i]);
    }
    bool bo=memo[k-1];
    rep(i, k, n) {
        auto a = st.lower_bound(vec[i - k]), b = st.upper_bound(vec[i]);
        if (a!=st.begin()||b != st.end()) {
            ans=ans+1-memo[i];
            if(memo[i]&&!bo){
                bo=true;
                ans++;
            }
        }
        st.erase(vec[i - k]);
        st.insert(vec[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 12800
import collections
import numpy as np

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

A = np.array(A,dtype='int64')
C = np.append([0],np.cumsum(A))
L = [i%M for i in C]
L_c = collections.Counter(L)

ans = 0
for i in L_c.values():
    S = i * (i-1) / 2
    ans+=S
    
print(int(ans))

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100100;

int A[MAX];

LL RES[MAX];

int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false); cin.tie(0);

	int n;
	//scanf("%d", &n);
	cin>>n;
	set<PII> s;
	A[0] = 0;
	s.insert(MP(0, 0));
	n++;
	FOR (i, 1, n)
	{
		//scanf("%d", &A[i]);
		cin>>A[i];
		s.insert(MP(-A[i], i));
	}

	PII a = *s.begin();

	int ind = a.second-1;
	map<int, int> m;

	FOR (i, ind+1, n)
	{
		s.erase(MP(-A[i], i));
		m[-A[i]]++;
	}

	int pind = ind + 1;

	while(SZ(s))
	{
		PII a = *s.begin();
		int pos = a.second;
		int val = -a.first;
		while(ind >= pos)
		{
			s.erase(MP(-A[ind], ind));
			m[-A[ind]]++;
			ind--;
		}

		LL res = 0;

		while(SZ(m) && -m.begin()->first > val)
		{
			PII a = *m.begin();
			m.erase(m.begin());


			res += (-a.first - val)*(LL)a.second;
			m[-val] += a.second;
		}

		RES[pind] += res;
		pind = ind + 1;
	}

	FOR (i, 1, n)
	{
		//printf("%lld\n", RES[i]);
		cout<<RES[i]<<"\n";
	}

}


Measured memory_bytes: 7040
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;

// ------ graph ------ //
using Weight = int;
using Array = vector<Weight>;
using Matrix = vector<Array>;

// ------ WarshallFloyd ------ //
void WarshallFloyd(Matrix &d) {
    int n = d.size();
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
            if (d[i][k] != INF && d[k][j] != INF) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int n, m; cin >> n >> m;
    Matrix dist(n, vector<Weight>(n, INF));
    for (int i = 0; i < n; i++) dist[i][i] = 0;
    vector<int> a(m), b(m), c(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i]; a[i]--, b[i]--;
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }

    WarshallFloyd(dist);

    int cnt = 0;
    for (int i = 0; i < m; i++) {
        if (dist[a[i]][b[i]] < c[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int N, K;
    string S;
    cin >> N >> K >> S;

    vector<int> cons;
    char cur = S[0];
    int cnt = 0;
    REP(i, N) {
        if(cur == S[i]) {
            cnt++;
        }
        else {
            cons.push_back(cnt);
            cnt = 1;
        }
        cur = S[i];
    }
    cons.push_back(cnt);

    // 左から K つを統合
    cnt = 0;
    int cand1 = 0;
    REP(i, cons.size()) {
        if(i < 2 * K) {
            cnt += cons[i];
        }
        else {
            if(i == 2 * K) {
                cnt += cons[i];
                cand1 += cnt - 1;
                cnt = 0;
            }
            else {
                cand1 += cons[i] - 1;
            }
        }
    }
    if(cnt > 0) {
        cand1 += cnt - 1;
    }

    // 右から K つを統合
    cnt = 0;
    int cand2 = 0;
    for(int i = cons.size() - 1; i >= 0; --i) {
        if(i > cons.size() - 2 * K) {
            cnt += cons[i];
        }
        else {
            if(i == cons.size() - 2 * K) {
                cand2 += cnt - 1;
                cnt = 0;
            }
            else {
                cand2 += cons[i] - 1;
            }
        }
    }
    if(cnt > 0) {
        cand2 += cnt - 1;
    }

    int ans = max(cand1, cand2);
    printf("%lld\n", ans);

    return 0;
}


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

template <typename T>
void print(const T &v);

int main()
{
    int n, W;
    cin >> n >> W;
    vector<int> v(n), w(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i] >> w[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(W + 1, 0));

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            // cout << i << ':' << j << endl;
            if (j - w[i - 1] < 0)
            {
                dp[i][j] = dp[i - 1][j];
                continue;
            }
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
        }
    }
    // for (int i = 0; i <= n; i++)
    // {
    //     print(dp[i]);
    // }
    cout << dp[n][W] << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 6828
/* NotQuiteMyTempo */
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false); cin.tie(NULL)

int main(){
   int n, m, sum = 0;
   cin >> n >> m; 
   
   sum += ( n * (n - 1) ) / 2;
   sum += ( m * (m - 1) ) / 2;
   
   cout << sum;
return 0;
}  

Measured memory_bytes: 256
ri = lambda: map(int, raw_input().split())
input()
d = dict()
for x in ri():
    if x not in d:
        d[x] = 0
    d[x] += 1
input()
for x in ri():
    if x not in d or d[x] == 0:
        print 'NO'
        quit()
    d[x] -= 1
print 'YES'



Measured memory_bytes: 37088
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#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 SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
 
 
//ここから編集
 
const int MAX = 2000010;
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
ll modPow(ll x, ll n, ll mod = MOD){
    ll res = 1;
    while(n){
        if(n&1) res = (res * x)%mod;
 
        res %= mod;
        x = x * x %mod;
        n >>= 1;
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  
    int K; string s; cin >> K >> s;
 
    COMinit();
 
    ll ans = 0;
    for(int i=0; i<=K; i++){
        ans %= MOD;
        ans += modPow(26, i, MOD) * modPow(25, K-i, MOD) % MOD* COM(K-i + s.size()-1, K-i) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 51180
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(void){
    string input;
    
    while(getline(cin, input), !cin.eof()){
        int n = atoi(input.c_str());
        int h, m, s;
        
        h = n / (60 * 60);
        m = (n % (60 * 60)) / 60;
        s = n % 60;
        
        printf("%d:%d:%d\n", h, m, s);
    }
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N,K,R=0;
	cin >> N >> K;
	vector<int> H(N);
	for (int i=0; i<N; i++){
		cin >> H.at(i);
	}
	for (int i=0; i<N; i++){
		if (H.at(i) >= K){
			R ++;
		}
	}
	cout << R << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int n;
  cin >> n;
  int a[n];
  int ans = 0;
  for (int i = 0; i < n; i++){
    cin >> a[i];
    if ((a[i] % 2) != 0){
      cout << ans << endl;
      return 0;
    }
  }

  while (true){
    for (int i = 0; i < n; i++){
      if ((a[i] % 2) != 0){
        cout << ans << endl;
        return 0;
      }
      else {
        a[i] = a[i] / 2;
      }
    }
    ans += 1;
  }

  return 0;
}


Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
n = ii()
A = iil()
ans = 1
if 0 in A:
    print(0)
    exit()
for item in A:
    ans *= item
    if ans > 1e18:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 21788
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
long long N, A[1 << 18];
 
int main() {
	cin >> N; long long S = 0;
	for (int i = 1; i <= N; i++) { cin >> A[i]; S += A[i]; }
 
	long long minx = S, sum = 0;
	for (int i = 1; i <= N; i++) {
		sum += A[i];
		minx = min(minx, abs(sum - (S - sum)));
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, tmp;
    string s="abcdefghijklmnopqrstuvwxyz", ans="";
    cin >> n;
    tmp=n;
    while(tmp>0){
        tmp--;
        ans+=s[(tmp%26)];
        tmp/=26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans <<endl;
}

Measured memory_bytes: 3628
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;


public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var color = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();

        List<int>[] graph = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < n - 1; i++)
        {
            var st = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            graph[st[0]].Add(st[1]);
            graph[st[1]].Add(st[0]);
        }

        int[] subTreeSize = new int[n];
        int getSubTreeSize(int node, int parent)
        {
            foreach (var item in graph[node])
            {
                if (item == parent) continue;
                subTreeSize[node] += getSubTreeSize(item, node);
            }
            return ++subTreeSize[node];
        }
        getSubTreeSize(0, -1);

        long[] res = new long[n];
        State[] states = Enumerable.Range(0, n).Select(x => new State() { Color = x, Size = n }).ToArray();
        void dfs(int node, int parent)
        {
            var forRootChunkSize = states[color[node]].Size - subTreeSize[node];
            foreach (var item in graph[node])
            {
                if (item == parent) continue;
                states[color[node]].Size = subTreeSize[item];
                dfs(item, node);
                res[color[node]] += states[color[node]].Size * (states[color[node]].Size - 1) / 2 + states[color[node]].Size;
            }
            states[color[node]].Size = forRootChunkSize;
        }
        dfs(0, -1);
        foreach (var state in states)
        {
            res[state.Color] += state.Size * (state.Size - 1) / 2 + state.Size;
        }
        long total = (long)n * (n - 1) / 2 + n;
        Console.WriteLine(string.Join("\n", res.Select(x => total - x)));
    }
}

class State
{
    public int Color;
    public long Size;
}



Measured memory_bytes: 102208
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    long[] v = new long[n];
    for(int i=0;i<n;i++)v[i]=sc.nextLong();
    Arrays.sort(v);
    long ans = 0;
    for(int i=1;i<=a;i++)ans+=v[n-i];
    long key = v[n-a];
    long k = 0;
    long m = 0;
    for(int i=0;i<n;i++)if(v[i]==key)m++;
    for(int i=1;i<=a;i++)if(v[n-i]==key)k++;
    System.out.println((double)ans/a);
    long cnt = 0;
    if(k<a)cnt = combination(m,k);
    else{
      for(int i=a;i<=b;i++)cnt+=combination(m,i);
    }
    System.out.println(cnt);
  }
  static long combination(long m,long k){
    long x = 1;
    for(long i=m;i>=m-k+1;i--)x=(x*i)/(m-i+1);
    return x;
  }
}

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

void dfs(long long a[],vector<int>v[],int r,bool visited[]){
    visited[r]=true;
    for(vector<int>::iterator it=v[r].begin();it!=v[r].end();it++){
        if(!visited[*it]){
            a[*it]+=a[r];
            dfs(a,v,*it,visited);
        }
    }
}

int main() {
	int n,q,A,B,p,x;
	cin>>n>>q;
	long long a[n];
	vector<int>v[n];
	bool visited[n];
	for(int i=0;i<n;i++){
	    a[i]=0;
	    visited[i]=false;
	}
	for(int i=1;i<=n-1;i++){
	    cin>>A>>B;
	    A--;
	    B--;
	    v[A].push_back(B);
	    v[B].push_back(A);
	}
	for(int i=1;i<=q;i++){
	    cin>>p>>x;
	    a[p-1]+=x;
	}
	dfs(a,v,0,visited);
	for(int i=0;i<n;i++){
	    cout<<a[i]<<' ';
	}
	return 0;
}

Measured memory_bytes: 27520
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>

using namespace std;

#define MOD 1000000007

typedef long long ll;

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

	vector<ll> x(n),y(m);
	for(int i=0;i<n;i++)
		cin >> x[i];
	for(int i=0;i<m;i++)
		cin >> y[i];

	ll xx=0;
	for(int i=0;i<n;i++)
	{
		xx+=(x[i]*i-x[i]*(n-i-1));
	}
	xx%=MOD;

	ll yy=0;
	for(int i=0;i<m;i++)
	{
		yy+=(y[i]*i-y[i]*(m-i-1));
	}
	yy%=MOD;

	ll ans=xx*yy;
	cout << ans%MOD << endl;


}

Measured memory_bytes: 1792
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
typedef long long ll;

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

const long long INF = 1LL << 60;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int main(void){
    int n;

    cin >> n;

    vector<ll> a(n + 1);

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

    vector<ll> b(n);
    
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }

    ll ans = 0;
    for(int i = n - 1; i >= 0; i--){
        if(a[i + 1] >= b[i]){
            ans += b[i];
            b[i] = 0;
        } else {
            ans += a[i + 1];
            b[i] -= a[i + 1];
            if(a[i] <= b[i]){
                ans += a[i];
                b[i] -= a[i];
                a[i] = 0;
            } else {
                a[i] -= b[i];
                ans += b[i];
                b[i] = 0;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>

void swap(int *a, int *b) {
	int c;
	c = *a, *a = *b, *b = c;
}

int main(void){
	int A, B, C;

	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);

	swap(&A, &B);
	swap(&A, &C);

	printf("%d %d %d\n", A, B, C);
	return 0;
}

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

using namespace std;
int gcd(int a,int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int sgcd(int a,int b,int c)
{
	int p = gcd(a,b);
  	return gcd(p,c);
}
int main()
{
  int k;
  int sum = 0;
  cin >> k;
  for(int i = 1;i <= k;i++)
  {
    for(int j = 1;j <= k;j++)
  	{
  		for(int s = 1;s <= k;s++)
  		{
  			sum += sgcd(i,j,s);
  		}
  	}
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

struct edge{
    int to, cost;
};

int main(){
    int H, W; cin >> H >> W;
    vector<vector<int>> c(10, vector<int>(10));

    rep(i,10){
        rep(j,10){
            cin >> c[i][j];
        }
    }

    rep(k,10){
        rep(i,10){
            rep(j,10){
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }

    vector<vector<int>> A(H, vector<int>(W,0));
    rep(i,H) rep(j,W) cin >> A[i][j];

    ll ans = 0;
    rep(i,H){
        rep(j,W){
            if (A[i][j] == -1) continue;
            ans += c[A[i][j]][1];
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 3764
#include <iostream>
using namespace std;
int main(void){
    int P,Q,R;
    cin >> P >> Q >> R;
    
    if(P>=Q&&P>=R){
        cout << Q+R<<endl;
        
    }else if(Q>=P&&Q>=R)
        cout << P + R<<endl;
    
    else{
        cout << P+Q<<endl;
        
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String[] youbi = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

		String str= scan.next();

		for(int i = 0; i < 7; i++) {
			if(youbi[i].equals(str)) {
				System.out.println(7 - i);
			}
		}



	}
}


Measured memory_bytes: 20820
#include <iostream>

using namespace std;
int main(void){
    
    int n;
    cin >> n;

    for(int i=1;i<=n;i++){
        if(i%3==0){
            cout << " " << i;
        }else{
            int j=i;
            while(j>1){
                if(j%10==3){
                   cout << " " << i;
                   break;
                }
                j /= 10;
            }
        }
    }
    cout << endl;


    return 0;
}



Measured memory_bytes: 3108
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

typedef std::complex<double> Com;

//geometric library
//#include <complex>
//typedef complex<double> Com;
//c++ -std=c++14

//内積
double dot_product(const Com a, const Com b){
	return (conj(a)*b).real();
}
//外積
double cross_product(const Com a, const Com b){
	return (conj(a)*b).imag();
}
//点と直線の距離
double dist_dot_line(const Com st, const Com en, const Com dt){
    return std::abs(cross_product(dt-st, en-st) / std::abs(en-st));
}
//点と線分の距離
double dist_dot_seg(const Com st, const Com en, const Com dt){
	if(dot_product(en-st, dt-st) <= 0){
		return std::abs(dt-st);
	}else if(dot_product(st-en, dt-en) <= 0){
		return std::abs(dt-en);
	}else{
		return dist_dot_line(st, en, dt);
	}
}
//線分の交差判定
bool seg_crossing(const Com st1, const Com en1, const Com st2, const Com en2){
	double cross1 = cross_product(en1-st1, st2-st1) * cross_product(en1-st1, en2-st1);
	double cross2 = cross_product(en2-st2, st1-st2) * cross_product(en2-st2, en1-st2);
	return (cross1 <= 0) && (cross2 <= 0);
}
//線分と線分の距離
double dist_seg(const Com st1, const Com en1, const Com st2, const Com en2){
	if(seg_crossing(st1, en1, st2, en2)){
		return 0;
	}
	return std::min(std::min(dist_dot_seg(st1, en1, st2), dist_dot_seg(st1, en1, en2)), std::min(dist_dot_seg(st2, en2, st1), dist_dot_seg(st2, en2, en1)));
}

Com p0, p1;
long q;
Com p2;

int main(){
    double xp1, yp1, xp2, yp2;
    scanf("%lf%lf%lf%lf", &xp1, &yp1, &xp2, &yp2);
    p0 = Com(xp1, yp1);
    p1 = Com(xp2, yp2);
    scanf("%ld", &q);
    for(int i = 0; i < q; i++){
        double x, y;
        scanf("%lf%lf", &x, &y);
        p2 = Com(x, y);
        Com a = p1 - p0;
        Com b = p2 - p0;
        if(cross_product(a, b) > 0){
            printf("COUNTER_CLOCKWISE\n");
        }else if(cross_product(a, b) < 0){
            printf("CLOCKWISE\n");
        }else{
            if(a == 0.0 || b == 0.0){
                printf("ON_SEGMENT\n");
            }else if(dot_product(a, b) < 0){
                printf("ONLINE_BACK\n");
            }else{
                if(abs(a) < abs(b)){
                    printf("ONLINE_FRONT\n");
                }else{
                    printf("ON_SEGMENT\n");
                }
            }
        }
    }
}



Measured memory_bytes: 3268
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){
   
   int n;
   cin>>n;
   char s_;
   vector<int> s_num(n);
   vector<vector<int>> rgb(3);
   ll count = 1;
   rep(i,n) {
       cin >> s_;
       if(s_ == 'R') {
           rgb[0].push_back(i);
           s_num[i] = 0;
       }
       else if(s_ == 'G') {
           rgb[1].push_back(i);
           s_num[i] = 1;
       }
       else if(s_ == 'B') {
           rgb[2].push_back(i);
           s_num[i] = 2;
       }
   }
   vector<int> cnt(3);
   rep(i,n) cnt[s_num[i]]++;
   rep(i,3) count *= cnt[i];//RGBが異なる組み合わせ数
   rep(j,n)rep(i,j){
       int k=j+(j-i);
       if(k<n){
           if(s_num[i]==s_num[j]) continue;
           if(s_num[i]==s_num[k]) continue;
           if(s_num[k]==s_num[j]) continue;
           count--;
       }
   }

   cout << count;
   /*
   int aa[3][2];
   aa[0][0]=1;  aa[0][1]=2;
   aa[1][0]=0;  aa[1][1]=2;
   aa[2][0]=0;  aa[2][1]=1;
 
    for(int i = 0; i < n; i++){
         for(int x: rgb.at(aa[s_num[i]][0])){
              for(int y :  rgb.at(aa[s_num[i]][1])){
                if((y-x != x-i) && (y > x)) count++;
                else if((x-y != y-i) && (x > y)) count++;
               }
           }
           rgb.at(s_num[i]).erase(rgb.at(s_num[i]).begin());
    }
 
    cout << count;
 
   for(int i = 1; i < n; i++){
       for(int j = i+1; j < n; j++){
           for(int k = j +1; k < n; k++){
 
           }
       }
   }*/
 
    return 0;
}

Measured memory_bytes: 3620