akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"

#define rep(i,n) for (int i = 0; i < n; i++)
#define repd(i,n) for (int i = n-1; i >= 0; i--)
#define fo(i,a,b) for (int i = a; i < b; i++)
#define fod(i,a,b) for (int i = a; i >= b; i--)
#define umap unordered_map<int,int>
#define mii map<int,int>
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define pqMin priority_queue<int,vector<int>,greater<int>>
#define pqMax priority_queue<int>
#define pqpii priority_queue<pii>
#define all(v) v.begin(),v.end()
#define sortall(v) sort(all(v))
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define w(t) int t; cin>>t; while (t--)
#define out(x, y) cout << x << " " << y << endl
#define print(x) cout << x << endl
#define ps(x,y) fixed<<setprecision(y)<<x
#define pprint cout<<"Case #"<<tt<<": ";
const int mod = 1e9+7;
const int N = 2e5;
const int inf = 1e18;

int add(int a,int b){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
bool compare (int x, int y) { return x > y;}

struct Compare {
    bool operator () (pii A, pii B) {
        return A.first > B.first;
    }
};
 struct tri{
   int x,y,z;
 };
 struct cmp{
bool operator ()(tri a,tri b){
    if(a.x==b.x)
        return a.y>b.y;
    return a.x<b.x;

}};
bool comp(pii a,pii b){
    if(a.first>b.first) return true;
    else if(a.first==b.first) return a.second<b.second;
    else return false;

}
int binarySearch(vector<int>nums, int lo, int hi, int target) {
        while (lo < hi) {
            int mid = (lo + hi)/2;
            if (nums[mid] <= target) {
                lo = mid + 1;
            } else {
                hi = mid;
            }
        }
        return lo;
    }

void solve() {

    int t = 1;
    //cin >> t;
    while(t--){
      int n;
      cin>>n;
      int s=0,ans=0;
      vector<int>v(n);
      for(int i=0;i<n;i++){
        cin>>v[i];
        s=(s+v[i])%mod;
      }
      for(int i=0;i<n;i++){
        s=(s-v[i]+mod)%mod;
        ans=(ans+((s*v[i])%mod))%mod;
      }
      cout<<ans;

    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);1

    freopen("output.txt", "w", stdout);
    #endif*/

    solve();

    return 0;
}


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

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

  int DP[N + 1][W + 1];

  for (int j = 0; j <= W; j++)
    {
      DP[0][j] = 0;
    }

  for (int i = 1; i <= N; i++)
    {
      for (int j = 0; j <= W; j++)
	{
	  if (j < w[i - 1])
	    {
	      DP[i][j] = DP[i - 1][j];
	    }
	  else
	    {
	      if (DP[i - 1][j] > DP[i][j - w[i - 1]] + v[i - 1])
		{
		  DP[i][j] = DP[i - 1][j];
		}
	      else
		{
		  DP[i][j] = DP[i][j - w[i - 1]] + v[i - 1];
		}
	    }
	}
    }

  cout << DP[N][W] << endl;

  return 0;
}

Measured memory_bytes: 7020
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.size(),ff=1;
    for(int i=0;i<=25;i++)
    {
        char k=i+'a';
        int flag=1,pos;
        for(int j=0;j<n;j++)
        {
            if(t[j]==k)
            {
                if(flag) pos=j,flag=0;
                else
                {
                    if(s[pos]!=s[j]&&s[j]!=t[j])
                    {
                        ff=0;break;
                    }
                }
            }
        }
        if(!ff) break;
    }
    if(!ff)
    {
        printf("No\n");
        return 0;
    }
    for(int i=0;i<=25;i++)
    {
        char k=i+'a';
        int flag=1,pos;
        for(int j=0;j<n;j++)
        {
            if(s[j]==k)
            {
                if(flag) pos=j,flag=0;
                else
                {
                    if(t[pos]!=t[j]&&t[j]!=s[j])
                    {
                        ff=0;break;
                    }
                }
            }
        }
        if(!ff) break;
    }
    if(!ff) printf("No\n");
    else printf("Yes\n");
}


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

int main() {
    int n,x,p=1;
    cin>>n;
    rep(i,n){
        cin>>x;
        if(x==p) p++;
    }
    if(p==1) printf("-1");
    else cout<<n-p+1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <climits>

using namespace std;

int main(){
    int n; cin >> n;
    string s, t; cin >> s >> t;
    for(int i=0; i<n; ++i){
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

const int N = 38;

vi a[N*(N-1)+1];

int main(){

  a[0].pb(0);
  REP( i , N ){
    REP( j , N-1 ){
      a[i*(N-1)+j+1].pb(i);
    }
  }
  REP( i , N ){
    REP( j , N-1 ){
      a[i].pb(i*(N-1)+j+1);
    }
  }
  REP( i , N-1 ){
    REP( j , N-1 ){
      REP( k , N-1 ){
        int p = N + ( N - 1 ) * k + ( j + i * k ) % ( N - 1 );
        a[p].pb( N + i * ( N - 1 ) + j );
      }
    }
  }

  /*
  REP( i , N*(N-1)+1){
    REP( j , i ){
      ll s = 0;
      ll t = 0;
      YYS( w , a[i] ){
        s = s | PW(w);
      }
      YYS( w , a[j] ){
        t = t | PW(w);
      }
      assert( __builtin_popcountll(s) == N );
      assert( __builtin_popcountll(t) == N );
      if( __builtin_popcountll(s & t) != 1 ){
        cout << i << " " << j << endl;
      }
      // assert( __builtin_popcountll(s & t) == 1 );
    }
  }
  */
  
  printf( "%d %d\n", N*(N-1)+1, N );
  REP( i , N*(N-1)+1 ){
    REP( j , SZ(a[i]) ){
      if( j != 0 ){
        printf( " " );
      }
      printf( "%d", a[i][j] + 1);
    }
    printf( "\n" );
  }
  
  return 0;
}


Measured memory_bytes: 896
#include<stdio.h>

int main(void) {
	int s[4];
	int i;

	for (i = 0;i < 4;i++) {
		scanf("%1d", &s[i]);
	}

	int count = 0;

	for (i = 0;i < 3;i++) {
		if (s[i] == s[i + 1]) {
			count++;
		}
	}

	if (count == 0) {
		printf("Good\n");
	}
	else {
		printf("Bad\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int n, k;
    cin >> n >> k;
    vector<ll> cost(n);
    vector<int> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p[i];
        p[i]--;
    }
    for(int i = 0; i < n; ++i){
        cin >> cost[i];
    }
    vector<ll> sums;
    auto dfs = [&sums, &p, &cost](const auto &lambda, int I, int u, ll ans)->void{
        //printf("cost[%d] = %lld\n", 1+u, cost[u]);
        if(u == I){
            ans += cost[u];
            sums.push_back(ans);
            return;
        }
        ans += cost[u];
        sums.push_back(ans);
        lambda(lambda, I, p[u], ans);
    };
    ll best = 0;
    bool not_set = true;
    for(int i = 0; i < n; ++i){
        sums.clear();
        dfs(dfs, i, p[i], 0);
        ll ans = sums[0];
        //for(auto kk : sums){
            //cerr << kk << " ";
        //}
        //cerr <<endl;
        if(k > (int)sums.size()){
            for(int j = 1; j < (int)sums.size(); ++j){
                ans = max(ans, sums[j]);
            }
            if(sums.back() > 0){
                int rem = k % (int)sums.size();
                ans = max(ans, 1LL * sums.back() * (k/(int)sums.size()));
                for(int j = 0; j < rem; ++j){
                    ans = max(ans, 1LL * sums.back() * (k/(int)sums.size()) + sums[j]);
                }
                ans = max(ans, 1LL * sums.back() * max(0, ((k/(int)sums.size()) - 1)) + *max_element(sums.begin(), sums.end()));
            }
        }
        else{
            for(int j = 1; j < k; ++j){
                ans = max(ans, sums[j]);
            }
        }
        if(not_set){
            not_set = false;
            best = ans;
        }
        best = max(best, ans);
    }
    cout << best << endl;


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

    solve();
}


Measured memory_bytes: 4136
//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define fastio                      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define   endl                      "\n"

int main()
{
	string s;
	cin >> s;
	cout << s;
	if(s.back()=='s'){
		cout<<"es";
	}else{
		cout<<"s";
	}
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdlib>


int MtoD(int Year, int Month) {
    if (Year % 3 == 0) {
        return 20;
    } else {
        if (Month % 2 == 1) {
            return 20;
        }
    }
    return 19;
}
int YtoD(int Year) {
    int total = 0;
    for (int i = 1; i <= 10; i++) {
        total += MtoD(Year, i);
    }
    return total;
}

void calc(int Year, int Month, int Day) {
   int y = 999 - Year;
   int q_y = y / 3;
   int r_y = y % 3;
   int total = q_y * 590;
   for (int i = 1; i <= r_y; i++) {
    total += YtoD(Year + i);
   }
   for (int i = Month + 1; i <= 10; i++) {
    total += MtoD(Year, i);
   }
   total += MtoD(Year, Month) - Day + 1;
   std::cout << total << std::endl;
}

int main(void) {
    int n;
    int Y;
    int M;
    int D;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        std::cin >> Y >> M >> D;
        calc(Y, M, D);
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3068
use proconio::input;

#[allow(non_snake_case)]
fn dfs(X: &mut Vec<i32>, L: &Vec<i32>, A:i32, B: i32, C: i32, N:usize) -> i32{ 
    if X.len() == N {
        let mut mp = 0;
        let mut length_a = 0;
        let mut length_b = 0;
        let mut length_c = 0;
        for (l, x) in L.iter().zip(X) {
            if *x == 0 {
                if length_a > 0 {
                    mp += 10;
                }
                length_a += l;
            } else if *x == 1 {
                if length_b > 0 {
                    mp += 10;
                }
                length_b += l;
            } else if *x == 2{
                if length_c > 0 {
                    mp += 10;
                }
                length_c += l;
            }
        }
        mp += (A - length_a).abs() + (B - length_b).abs() + (C - length_c).abs();
        if length_a == 0 || length_b == 0 || length_c == 0 {
            mp = 100_000_000;
        }
        return mp;
    } else {
        let mut ret = 100_000_000;
        for i in 0..4 {
            X.push(i);
            ret = dfs(X, L, A, B, C, N).min(ret);
            X.pop();
        }
        return ret;
    }
}

#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        A: i32,
        B: i32,
        C: i32,
        L: [i32; N]
    }
    let mut X: Vec<i32> = Vec::new();
    let ans = dfs(&mut X, &L, A, B, C, N);
    println!("{}", ans);
}

Measured memory_bytes: 2164
//
// Created by rajshah9914 on 05/04/20.
//

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long ans=0;
    for(long long i=1;i*i<=n-1;i++)
    {
        if((n-1)%i==0)
        {
            if(i>1)
                ans++;
            if((n-1)/i!=i)
                ans++;
        }
    }
    auto check = [&](long long v)
    {
        long long x=n;
        while(x%v==0)
            x/=v;
        if(x%v==1)
            ans+=1;
    };

    for(long long i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(i>1)
                check(i);
            if(i!=n/i)
                check(n/i);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int sx = Integer.parseInt(scan.next());
	int sy = Integer.parseInt(scan.next());
	int tx = Integer.parseInt(scan.next());
	int ty = Integer.parseInt(scan.next());

	int h = ty - sy;
	int w = tx - sx;

	StringBuilder str = new StringBuilder();
	for (int i = 0; i < h; i++) str.append('U');
	for (int i = 0; i < w; i++) str.append('R');
	for (int i = 0; i < h; i++) str.append('D');
	for (int i = 0; i < w; i++) str.append('L');

	str.append('L');
	for (int i = 0; i < h+1; i++) str.append('U');
	for (int i = 0; i < w+1; i++) str.append('R');
	str.append('D');
	str.append('R');
	for (int i = 0; i < h+1; i++) str.append('D');
	for (int i = 0; i < w+1; i++) str.append('L');
	str.append('U');

	System.out.println(str.toString());
	scan.close();
    }
}


Measured memory_bytes: 21972
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

template<class T>
ostream& operator<< (ostream& fout, const vector<T>& vec) {
  for (const auto& el : vec) {
    fout << el << ' ';
  }
  return fout;
}

template <class T>
istream& operator>> (istream& fin, vector<T>& vec) {
  for (size_t i = 0; i < vec.size(); ++i) {
    cin >> vec[i];
  }
  return fin;
}

int solve(string s, int64_t& res) {
  if (s == "") return 0;
  int n = s.size();
  res += std::stoll(s);
  int cc = 0;
  for (int i = 1; i < n; ++i) {
    int tmp = std::stoll(s.substr(0, i));
    int c =  solve(s.substr(i, n), res);
    res += (c + 1) * tmp;
    cc += c + 1;
  }
  return cc;
}

int Solve() {
  string s;
  cin >> s;
  int64_t res = 0;
  solve(s, res);
  cout << res << '\n';
  return 0;
}


int main() {
#ifndef LOCAL
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
#endif
#ifdef LOCAL
  //freopen("input.txt", "rt", stdin);
#endif

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  Solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)1e9 + 5)
#define MAXL ((ll)1e15 + 5)
#define MAX_X ((int)1e5 + 2)
#define pi (2.0*acos(0))
#define M ((int)1e6 + 7)
#define MOD ((int)998244353 + 0)
#define NN ((int)1e5 + 7)
#define N ((int)1e5 + 5)
#define eps (0)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 29
#define endl "\n"
#define mp make_pair
//#define int ll


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/




typedef tree < pair < int, pair < int, int > >,  null_type,  less < pair < int, pair < int, int > > >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).

bool cmp(int a , int b)
{
    return a>b;
}

int arr[N];

int srch(int l , int r , int arr[], int a)
{
    while(l<r){
        int m = (l+r+1)>>1;
        if(arr[m]>a) l = m;
        else r = m - 1;
    }
    if(arr[l]>a) return l+1;
    return l;
}

ll cum[N];

int main()
{
    fastio;
    int n , m , v , p;
    cin>>n>>m>>v>>p;
    for(int i = 1 ; i<=n ; i++){
        cin>>arr[i];
    }
    sort(arr+1,arr+n+1,cmp);
    for(int i = 1 ; i<=n ; i++) cum[i] = cum[i-1] + arr[i];
    int ans = 0;
    for(int i = 1; i<=n; i++){
        if(arr[i]>=arr[p]) ans++;
        else if(arr[i]+m>=arr[p]){
            int pos = srch(1,n,arr,arr[i]);
            int tot = n-pos;
            ll rem = v - tot - p;
            rem *= m;
            ll sum = cum[pos-1]-cum[p-1];
            sum = (ll)(pos-1-p+1)*(arr[i]+m) - sum;
            if(sum>=rem) ans++;
        }
        //else cout<<arr[i]<<" ";
    }
   // cout<<endl;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 1001000
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    ll n;cin>>n;
    bool flag=true;
    while(n)
    {
        if(n%10==7)
        {
            flag=false;
            break;
        }
        n/=10;
    }
    if(!flag)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
	int n;
	long long int m[3];
	int i,j,k;
	long long int a,b;
	char c;
	cout<<"? 10000000001"<<endl;
	cin>>c;
	if(c=='Y'){
		a=1;
		for(i=0;i<12;i++){
			cout<<"? "<<a+1<<endl;
			cin>>c;
			if(c=='Y')break;
			a*=10;
		}
		cout<<"! "<<a<<endl;
		return 0;
	}
	a=10;
	for(n=1;;n++,a*=10){
		cout<<"? "<<a<<endl;
		cin>>c;
		if(c=='N')break;
	}
	m[0]=a,m[2]=a*10-1;
	while(1){
		if(m[2]-m[0]<=1)break;
		m[1]=(m[0]+m[2])/2;
		cout<<"? "<<m[1]<<endl;
		cin>>c;
		if(c=='Y')m[2]=m[1];
		else m[0]=m[1];
	}
	m[2]/=10;
	while(m[2]>1000000000){
		m[2]/=10;
	}
	cout<<"! "<<m[2]<<endl;
	return 0;
}
		


Measured memory_bytes: 596
N = int(input())
A = list(map(int, input().split()))
L = [0] * (N+1)
L[0] = 3
ans = 1
mod = 10**9+7
for a in A:
    ans = ans * L[a] % mod
    L[a]-=1
    L[a+1]+=1
print(ans)


Measured memory_bytes: 14020
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, d[10000], i, ans=0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> d[i];
    }
    for(i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ans+=d[i]*d[j];
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int h, w, n, a[1100], mp[1100][1100], cnt = 0, now = 0;
int main() {
    scanf("%d%d%d", &h, &w, &n);
    /*for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }*/
    for(int i = 1; i <= h; i++) {
        int from = (i & 1) ? 1 : w;
        int to = (i & 1) ? w + 1 : 0;
        int delta = (i & 1) ? 1 : -1;
        for(int j = from; j != to; j += delta) {
            if(cnt == 0) {
                now++;
                scanf("%d", &cnt);
            }
            mp[i][j] = now;
            cnt--;
        }
    }
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j < w; j++) {
            printf("%d ", mp[i][j]);
        }
        printf("%d\n", mp[i][w]);
    }
    return 0;
}



Measured memory_bytes: 768
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def main():
    n = int(input())
    As = list(map(int, input().split()))

    ans = float("inf")
    for i in range(n):
        if factorization(As[i])[0][0] != 2:
            ans = 0
            break
        else:
            ans = min(ans, factorization(As[i])[0][1])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
import java.util.*;
public class Main {
	public static void main(String[] args) {	
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		if(s.equals("Sunny")) {
			System.out.println("Cloudy");
		}else if(s.equals("Cloudy")) {
			System.out.println("Rainy");
		}else {
			System.out.println("Sunny");
		}
		
   }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(int i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define vinn(n,v) int n;cin>>n;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define vinm(n,m,v) int n,m;cin>>n>>m;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define debug(x) cerr<<#x<<" : "<<x<<endl;
mt19937 rd(time(0)); // i = rd%n
int gcd(int a,int b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}
signed main() 
{
    fastio();

    int n;
    cin>>n;
    int ans = 0;
    for(int i = 1;i<=n;i++)
    {
        for(int j = 1;j<=n;j++)
        {
            for(int k = 1;k<=n;k++)
            {
                // cout<<i<<" "<<j<<" "<<k<<endl;
                ans+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
using namespace std;
long long x, y, ans = 100;
int main()
{
	scanf("%lld", &x);
	while(ans < x)
	{
		ans *= 1.01;
		y++;
	}
	printf("%lld", y);
	return 0;
}

Measured memory_bytes: 3792
a, b, c, d = map(int, input().split())

ans = -float("INF")  # 答えがマイナスになることがあるので、負の無限大を初期値にしておきます

for x in (a, b):
    for y in (c, d):
        ans = max(ans, x * y)

print(ans)

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

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 + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

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

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

    vector<int> a(n+1);
    vector<int> b(n+1);

    rep1(i,n) b[i]=0;

    rep1(i,n-1){
         cin >> a[i];
         b[a[i]]++;
    }

    rep1(i,n) cout << b[i] << endl;

}

Measured memory_bytes: 4788
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


H, W = inpl()
mass = []
for i in range(H):
    mass.append(inpl())

count = 0
ans = []
for i in range(H):
    for j in range(W):
        if mass[i][j] & 1:
            if j < W - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 1, j + 2])
                mass[i][j] -= 1
                mass[i][j + 1] += 1
            elif i < H - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 2, j + 1])
                mass[i][j] -= 1
                mass[i + 1][j] += 1

print(count)
for a in ans:
    print(' '.join(map(str, a)))

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

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

    int n;
    cin >> n;
    map<int, int> series;
    rep(i, n) {
        int input;
        cin >> input;
        if (series.find(input) != series.end()) {
            series[input]++;
        } else {
            series[input] = 1;
        }
    }

    if (series.size() == n) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
using namespace std;

using i64 = long long;
using f64 = double;
using pii = pair<int, int>;
using pq = priority_queue<i64>;

static char q(int x) {
	static string str;

	cout << x << endl;
	cin >> str;

	if (str == "Vacant")
		exit(0);

	return str[0]; }

int main() {
	int n, s, tq, t(0);
	cin >> n;

	s = q(0);
	for (int msk = 1 << 20; msk > 0; msk/= 2) if (t + msk < n) {
		tq = q(t + msk);
		if (msk == 1) {
			if (tq != s)
				t+= msk; }
		else if (tq == s)
			t+= msk; }

	q(t + 1);

	return 0; }


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<int> prime;
bool is_prime[1000010];
int min_factor[1000010];
int sieve(int n) {
  fill(is_prime + 2, is_prime + 1000010, true);
  min_factor[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.emplace_back(i);
      for (int j = 2 * i; j <= n; j += i) {
        is_prime[j] = false;
        if (min_factor[j] == 0) min_factor[j] = i;
      }
    }
  }
  return prime.size();
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  sieve(50000);
  int pz = prime.size(), cnt[50010] = {};
  for (int i = 0; i < pz; i++) {
    for (int j = i; j < pz && prime[i] + prime[j] <= 50000; j++) {
      cnt[prime[i] + prime[j]]++;
    }
  }

  int n;
  while (cin >> n, n) {
    cout << cnt[n] << endl;
  }

  return 0;
}


Measured memory_bytes: 4580
import java.util.Scanner;

public class Main {

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

		int y = (1900 * m + 100 * (n - m)) * (int) Math.pow(2, m);
		System.out.println(y);
		sc.close();
	}

}


Measured memory_bytes: 21716
fun main() {
    var ac = 0
    var wa = 0
    var tle = 0
    var re = 0
    repeat(nextInt()) {
        when (next()) {
            "AC" -> ac++
            "WA" -> wa++
            "TLE" -> tle++
            "RE" -> re++
        }
    }
    println("AC x $ac")
    println("WA x $wa")
    println("TLE x $tle")
    println("RE x $re")
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

Measured memory_bytes: 56748
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int n, k;
    string s;
    cin >> n >> k >> s;

    s[k-1] = s[k-1] + 'a' - 'A';
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;

int main(){
  int n;
  scanf("%d", &n);
  vector<int> num(n);
  REP(i, n){
    scanf("%d", &num.at(i));
  }

  bool result = true;
  REP(i, n){
    if (num.at(i) % 2 == 0){
      if (num.at(i) % 3 != 0 && num.at(i) % 5 != 0){
        result = false;
      }
    }
  }

  if (result) printf("APPROVED\n");
  else printf("DENIED\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

vvl G = vv(100001, 0, 0, ll);
vll c(100001, 0), road(100001, 0), d(100001, 0);
ll n;
bool dfs(ll now, ll from, ll D){
  d[now] = D;
  if(now==n){
    road[now] = 1;
    return true;
  }
  bool ret = false;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    if(dfs(G[now][i], now, D+1)){
      road[now] = 1;
      ret = true;
    }
  }
  return ret;
}
void init(ll now, ll from){
  if(road[now]==1){
    if(d[now]<=d[n]-d[now]) c[now] = 1;
    else c[now] = -1;
  }
  for(int i=0;i<G[now].size();i++){
    if(G[now][i] == from ) continue;
    init(G[now][i], now);
  }
}
void dfs2(ll now, ll from ,ll C){
  if(c[now]!=0) C = c[now];
  else c[now] = C;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    dfs2(G[now][i], now, C);
  }
}
int main(int argc, char const *argv[]) {
  ll a, b;std::cin >> n;
  re(i, n-1){
    std::cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(1, -1, 0);
  init(1, -1);
  dfs2(1, -1, 1);
  ll ans=0;
  for(int i=1;i<=n;i++) ans+=c[i];
  std::cout << (ans<=0?"Snuke":"Fennec") << '\n';
  return 0;
}


Measured memory_bytes: 14336
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt(), B = sc.nextInt();
        char[][] c = new char[100][100];
        for(int i = 0; i < 100; i++){
            for(int j = 0; j < 50; j++){
                c[i][j] = '#';
            }
            for(int j = 50; j < 100; j++){
                c[i][j] = '.';
            }
        }
        
        int cntA = 1, cntB = 1;
        boolean flag1 =false, flag2 = false;
        if(A == 1) flag1 = true;
        if(B == 1) flag2 = true;
        for(int i = 0; i < 100; i += 2){
            if(flag1 == true) break;
            for(int j = 0; j < 49; j++){
                if((i + j) % 2 == 0){
                    c[i][j] = '.';
                    cntA++;
                    if(cntA == A){
                        flag1 = true;
                        break;
                    }
                }
            }
        }
        for(int i = 0; i < 100; i += 2){
            if(flag2 == true) break;
            for(int j = 51; j < 100; j++){
                if((i + j) % 2 == 0){
                    c[i][j] = '#';
                    cntB++;
                    if(cntB == B){
                        flag2 = true;
                        break;
                    }
                }
            }
        }
        System.out.println("100 100");
        for(int i = 0; i < 100; i++){
            for(int j = 0; j < 100; j++){
                System.out.print(c[i][j]);
            }
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 26812
import bisect

n=int(input())
l=list(map(int,input().split()))

l.sort()
ans=0
for i in range(n-1,1,-1):
    for j in range(i-1,0,-1):
        c=bisect.bisect_right(l,l[i]-l[j])
        #print(l[i],l[j],i,j,c)
        if j-c > 0:
            ans+=(j-c)
            
print(ans)


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int,int>> score(n);
    vector<int> result(n);
    for (int i = 0; i < n; ++i) {
        score[i].second = i;
    }
    for (int i = 0; i < (n * (n - 1)) / 2; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a;
        --b;
        if (c == d) {
            ++score[a].first;
            ++score[b].first;
        } else if (c > d) {
            score[a].first += 3;
        } else {
            score[b].first += 3;
        }
    }
    sort(score.rbegin(), score.rend());
    result[score[0].second] = 1;
    for (int i = 1; i < n; ++i) {
        if (score[i].first == score[i - 1].first) {
            result[score[i].second] = result[score[i - 1].second];
        } else {
            result[score[i].second] = i + 1;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << result[i] << '\n';
    }
}


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

#define int long long

using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int n;
int d[333][333];
int a[333][333];

void warshall_floyd(int n){
  rep(i,0,n)rep(j,0,n)rep(k,0,n){
    if(d[j][k]>d[j][i]+d[i][k])d[j][k]=d[j][i]+d[i][k];
  }
}


signed main(){
    cin>>n;
    rep(i,0,n){
        rep(j,0,n){
            cin>>d[i][j];
            a[i][j]=d[i][j];
        }
    }
    int ans=0;
    
    warshall_floyd(n);
    
    rep(i,0,n){
        rep(j,i+1,n){
            bool can=false;
            if(a[i][j]>d[i][j]){
                cout<<"-1"<<endl;
                return 0;
            }
            rep(k,0,n){
                if(k==i||k==j)continue;
                if(d[i][k]+d[k][j]==d[i][j])can=true;
            }
            if(!can)ans+=d[i][j];
            //cout<<d[i][j]<<" ";
        }
        //cout<<endl;
    }
    cout<<ans<<endl;
    
    
    
    
    return 0;
}

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

using namespace std;

void solve() {
    int ans = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 1; k <= n; ++k) ans += __gcd(i, __gcd(j, k));
        }
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using i64 = int64_t;

int main() {
    i64 n;
    cin >> n;

    vector<i64> a(n + 1);

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

    for (int i = 0; i < min(30, (int)a.size()); i++) {
        if (a[i] > (1 << i)) {
            cout << -1 << endl;
            return 0;
        }
    }

    if (n == 0) {
        if (a[0] == 1) {
            cout << 1 << endl;
        } else {
            cout << -1 << endl;
        }

        return 0;
    }

    if (a[0] != 0) {
        cout << -1 << endl;
        return 0;
    }

    vector<i64> b(n + 1), c(n + 1);
    b[n] = a[n];
    c[n] = a[n];

    for (i64 i = n - 1; i >= 0; i--) {
        b[i] = a[i] + (b[i + 1] + 1) / 2;
        c[i] = a[i] + c[i + 1];

        if (i < 63) {
            if (b[i] > (1LL << i)) {
                cout << -1 << endl;
                return 0;
            }

            if (c[i] > (1LL << i)) {
                c[i] = 1LL << i;
            }
        }
    }

    i64 ans = c[0];

    for (int i = 1; i <= n; i++) {
        c[i] = min(c[i], (c[i - 1] - a[i - 1]) * 2);
        ans += c[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 5192
/*https://atcoder.jp/contests/abc134/tasks/abc134_c*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int a[n], max_a, b[n];
	for (int i = 0; i < n; i++)
		cin >> a[i], b[i] = a[i];
	sort(b, b + n);
	reverse(b, b + n);
	int pos1, pos2;
	for (int i = 0; i < n; i++)
		if (a[i] == b[0])
			pos1 = i;
		else if (a[i] == b[1])
			pos2 = i;
	for (int i = 0; i < n; i++)
	{
		if (i == pos1)
			cout << b[1] << endl;
		else
			cout << b[0] << endl;
	}
}

Measured memory_bytes: 5072
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
template<typename T>
ostream& operator+(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out<<x<<" ";
    }
    out<<"\n";
    return out;
}
template<typename T>
ostream& operator*(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out+x;
    }
    return out;
}
template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}
const int lgn = 40;
void solve(){
    ll n,x,m;
    cin>>n>>x>>m;
    vector<array<ll,lgn>> dp1(m);
    vector<array<int,lgn>> dp2(m);
    for(int i=0;i<m;i++){
        dp1[i][0] = i;
        dp2[i][0] = (ll)i*i%m;
    }
    for(int j=1;j<lgn;j++){
        for(int i=0;i<m;i++){
            dp2[i][j] = dp2[dp2[i][j-1]][j-1];
            dp1[i][j] = dp1[i][j-1] + dp1[dp2[i][j-1]][j-1];
        }
    }
    ll ans = 0;
    while(n){
        int lg = __builtin_ctzll(n);
        n^=(1ll<<lg);
        ans+=dp1[x][lg];
        x = dp2[x][lg];
    }
    cout<<ans<<"\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 50184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll>A(N),T(N);
    rep(i,N){
        cin>>T[i]>>A[i];
    }

    ll nt=T[0],na=A[0];

    rep2(i,N-1){
        ll b=max((nt-1)/T[i]+1,(na-1)/A[i]+1);
        nt=b*T[i];
        na=b*A[i];
    }
    cout << na+nt << endl;


    return 0;
    

}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,m;
    cin>>n>>m;
    int a[55],b[55],c[55],d[55];
    for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
    for(int i=1;i<=m;i++)cin>>c[i]>>d[i];
    for(int i=1;i<=n;i++){
        int mind=INF,minj;
        for(int j=1;j<=m;j++){
            int dist=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(dist<mind){
                minj=j;
                mind=dist;
            }
        }
        cout<<minj<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int count=0;
    int a=0;
    int b=0;
    int n=sc.nextInt();
    int syo[]=new int[n];
    for(int i=0;i<n;i++){
      syo[i]=i+1;
    }
    int p[]=new int[n];
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    }

    for(int i=0;i<n;i++){
      if(syo[i]!=p[i]){
        count++;
      }
    }

    if(count==0){
      System.out.println("YES");
    }

    if(count==2){
      for(int i=0;i<n;i++){
        if(syo[i]!=p[i]){
          a=i;
          break;
        }
      }
      for(int i=a;i<n;i++){
        if(syo[i]!=p[i]){
          b=i;
        }
      }
      if(p[a]==syo[b] && p[b]==syo[a]){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }

    if(count!=0 && count!=2){
      System.out.println("NO");
    }

  }
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

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();}

typedef long long LL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve() {
  LL result = 0;
  int N;
  cin >> N;
  string s;
  unordered_map<string, int> answermap;
  REP0(i, N) {
    cin >> s;
    SORT(s);
    if (EXIST(answermap, s)) {
      result += answermap[s];
      answermap[s]++;
    } else {
      answermap[s] = 1;
    }
  }
  std::cout << result << endl;
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Measured memory_bytes: 10660
#include <iostream>

using namespace std;

int main()
{
     string arr[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  
     string S;
     int len = sizeof(arr)/sizeof(arr[0]);
     cin>>S;
     int i =0;
     for(i=0;i<len;i++){
        if(arr[i]==S){
            break;
        }
     }
     cout<<7-i<<endl;


    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

void solve() {
    int c[3][3];
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            scanf("%d", c[i]+j);
        }
    }
    for (int i = 1; i < 3; ++i) {
        for (int j = 1; j < 3; ++j) {
            if (c[i][j]-c[i][j-1] != c[0][j]-c[0][j-1]) {
                puts("No");
                return;
            }
        }
    }
    puts("Yes");
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define Mod 1000000000 + 7
#define Maxn 1000000 + 100
typedef long long ll;
using namespace std;
bool cmp(int x,int y)
{
    return x < y;
}

int gcd(int x,int y)
{
    return 0;
}

ll quick_mod()
{
    return 0;
}
ll n,ans,c[Maxn],s[Maxn],f[Maxn];
int main()
{
    cin>>n;
    for (int i = 1; i < n; i++)
        cin>>c[i]>>s[i]>>f[i];
    
    for (int i = 1; i < n; i++)
    {
        ans = c[i] + s[i];
        for (int j = i + 1; j < n; j++)
        {
            if( ans < s[j])
            {
                ans = c[j] + s[j];
            }
            else
                if( ans % f[j] != 0)
                {
                    ans = ( ans / f[j] + 1 ) * f[j]  + c[j];
                }
            else
            {
                ans += c[j];
            }
        }
        cout<<ans<<endl;
    }
    cout<<"0"<<endl;
    return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e9+1e7

int main()
{
    fastio;
    int n,w;
    cin >> n >> w;
    vector<int>we(n),va(n);
    for(int i=0;i<n;i++)
        cin >> we[i] >> va[i];
    int mval=0;
    for(int i=0;i<n;i++)
        mval+=va[i];
    lli dp[n+1][mval+1];
    for(int i=0;i<=mval;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(i==0)
            {
                dp[j][i]=0;
                continue;
            }
            if(j==0)
            {
                dp[j][i]=INF;
                continue;
            }
            lli t1=INF,t2=INF;
            if(va[j-1]<=i)
                t1=we[j-1]+dp[j-1][i-va[j-1]];
            t2=dp[j-1][i];
            dp[j][i]=min(t1,t2);
        }
    }
    int ans=0;
    //cout << mval << endl;
    //cout << dp[3][30] << endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=mval;j++)
        {
            if(dp[i][j]<=w)
                ans=j;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 79232
#include<cstdio>
#include<vector>
#define l(x) id[x]
#define r(x) id[x]+sz[x]-1
std::vector<int> a[200005];
int n,q,cnt,fa[200005],id[200005],sz[200005],ans[200005],s[200005];
void add(int x,int y){a[x].push_back(y);a[y].push_back(x);}
void dfs(int v)
{
	id[v]=++cnt;sz[v]=1;
	for (int i=0;i<a[v].size();i++)
	{
	    int u=a[v][i];
	    if (u==fa[v]) continue;
	    fa[u]=v;
	    dfs(u);
	    sz[v]=sz[v]+sz[u];
	}
}
void tag(int x,int v){s[l(x)]=s[l(x)]+v;s[r(x)+1]=s[r(x)+1]-v;}
int main()
{
	scanf("%d%d",&n,&q);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
	}
	dfs(1);
	while (q--)
	{
		int x,v;
		scanf("%d%d",&x,&v);
		tag(x,v);
	}
	for (int i=1;i<=n;i++) ans[i]=ans[i-1]+s[i];
	for (int i=1;i<=n;i++) printf("%d ",ans[id[i]]);
	return 0;
}

Measured memory_bytes: 33660